From 5ba88f5b683cf5cc5c5fd19512ed84235fe2d031 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 11 Jul 2016 13:40:36 +0200 Subject: Retry once if pid file is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gammad.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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')) -- cgit v1.2.3-70-g09d2