projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use our own port when connecting to ourself.
[tinc]
/
lib
/
pidfile.c
diff --git
a/lib/pidfile.c
b/lib/pidfile.c
index
2f30a4e
..
368dad4
100644
(file)
--- a/
lib/pidfile.c
+++ b/
lib/pidfile.c
@@
-25,14
+25,9
@@
* First version (v0.2) released
*/
* First version (v0.2) released
*/
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
+#include "system.h"
+#ifndef HAVE_MINGW
/* read_pid
*
* Reads the specified pidfile and returns the read pid.
/* read_pid
*
* Reads the specified pidfile and returns the read pid.
@@
-71,6
+66,7
@@
int check_pid (char *pidfile)
* be found -- GW
*/
/* But... errno is usually changed only on error.. */
* be found -- GW
*/
/* But... errno is usually changed only on error.. */
+ errno = 0;
if (kill(pid, 0) && errno == ESRCH)
return(0);
if (kill(pid, 0) && errno == ESRCH)
return(0);
@@
-93,13
+89,15
@@
int write_pid (char *pidfile)
fprintf(stderr, "Can't open or create %s.\n", pidfile);
return 0;
}
fprintf(stderr, "Can't open or create %s.\n", pidfile);
return 0;
}
-
+
+#ifdef HAVE_FLOCK
if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
fscanf(f, "%d", &pid);
fclose(f);
printf("Can't lock, lock is held by pid %d.\n", pid);
return 0;
}
if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
fscanf(f, "%d", &pid);
fclose(f);
printf("Can't lock, lock is held by pid %d.\n", pid);
return 0;
}
+#endif
pid = getpid();
if (!fprintf(f,"%d\n", pid)) {
pid = getpid();
if (!fprintf(f,"%d\n", pid)) {
@@
-109,11
+107,13
@@
int write_pid (char *pidfile)
}
fflush(f);
}
fflush(f);
+#ifdef HAVE_FLOCK
if (flock(fd, LOCK_UN) == -1) {
printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
close(fd);
return 0;
}
if (flock(fd, LOCK_UN) == -1) {
printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
close(fd);
return 0;
}
+#endif
close(fd);
return pid;
close(fd);
return pid;
@@
-128,4
+128,4
@@
int remove_pid (char *pidfile)
{
return unlink (pidfile);
}
{
return unlink (pidfile);
}
-
+#endif