X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=lib%2Fpidfile.c;h=2dea70b9ceed5f4ac617501fe329ffbff0dea830;hp=2f30a4e8aca14aa7e5dd07e097be96120535420f;hb=96ee04b678143defa1040f2defdd3424efedea11;hpb=1243156a5e03a666b36bc4400f1402243a85c9a7 diff --git a/lib/pidfile.c b/lib/pidfile.c index 2f30a4e8..2dea70b9 100644 --- a/lib/pidfile.c +++ b/lib/pidfile.c @@ -25,13 +25,7 @@ * First version (v0.2) released */ -#include -#include -#include -#include -#include -#include -#include +#include "system.h" /* read_pid * @@ -71,6 +65,7 @@ int check_pid (char *pidfile) * be found -- GW */ /* But... errno is usually changed only on error.. */ + errno = 0; if (kill(pid, 0) && errno == ESRCH) return(0); @@ -93,13 +88,15 @@ int write_pid (char *pidfile) 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; } +#endif pid = getpid(); if (!fprintf(f,"%d\n", pid)) { @@ -109,11 +106,13 @@ int write_pid (char *pidfile) } 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; } +#endif close(fd); return pid;