aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-11 13:40:36 +0200
committerMattias Andrée <maandree@kth.se>2016-07-11 13:40:36 +0200
commit5ba88f5b683cf5cc5c5fd19512ed84235fe2d031 (patch)
treefeda6d481d61d1a5bf00ee568f856bb588f788c4 /src
parentImplement use of PID file (diff)
downloadcoopgammad-5ba88f5b683cf5cc5c5fd19512ed84235fe2d031.tar.gz
coopgammad-5ba88f5b683cf5cc5c5fd19512ed84235fe2d031.tar.bz2
coopgammad-5ba88f5b683cf5cc5c5fd19512ed84235fe2d031.tar.xz
Retry once if pid file is empty
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/gammad.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gammad.c b/src/gammad.c
index ad1882e..fe1b004 100644
--- a/src/gammad.c
+++ b/src/gammad.c
@@ -217,7 +217,7 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
/* PORTERS: /proc/$PID/environ is Linux specific */
char temp[sizeof("/proc//environ") + 3 * sizeof(pid_t)];
- int fd = -1, saved_errno;
+ int fd = -1, saved_errno, tries = 0;
char* content = NULL;
char* p;
char* end;
@@ -225,6 +225,7 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
size_t n;
/* Get PID */
+ retry:
fd = open(pidfile, O_RDONLY);
if (fd < 0)
return -1;
@@ -233,6 +234,14 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
goto fail;
close(fd), fd = -1;
+ if (n == 0)
+ {
+ if (++tries > 1)
+ goto bad;
+ usleep(100000); /* 1 tenth of a second */
+ goto retry;
+ }
+
if (('0' > content[0]) || (content[0] > '9'))
goto bad;
if ((content[0] == '0') && ('0' <= content[1]) && (content[1] <= '9'))