From c30b64a63a2a4b22d1f51111e8fd2d82850d7985 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 23 Oct 2007 09:05:19 +0000 Subject: Allow half a second for a working pidfile to be created and a tenth of a second for a daemon to bail. --- src/start-stop-daemon.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/start-stop-daemon.c') diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 14bcdbb6..98e0e535 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -13,7 +13,8 @@ /* nano seconds */ #define POLL_INTERVAL 20000000 -#define START_WAIT 500000000 +#define WAIT_PIDFILE 500000000 +#define START_WAIT 100000000 #define ONE_SECOND 1000000000 #include @@ -974,8 +975,8 @@ int start_stop_daemon (int argc, char **argv) if (START_WAIT > 0) { struct timespec ts; int nloops = START_WAIT / POLL_INTERVAL; + int nloopsp = WAIT_PIDFILE / POLL_INTERVAL; bool alive = false; - bool retestpid = false; ts.tv_sec = 0; ts.tv_nsec = POLL_INTERVAL; @@ -989,7 +990,15 @@ int start_stop_daemon (int argc, char **argv) return (0); } } - nloops --; + + /* We wait for a specific amount of time for a pidfile to be + * created. Once everything is in place we then wait some more + * to ensure that the daemon really is running and won't abort due + * to a config error. */ + if (! background && pidfile && nloopsp) + nloopsp --; + else + nloops --; /* This is knarly. If we backgrounded then we know the exact pid. @@ -1005,9 +1014,8 @@ int start_stop_daemon (int argc, char **argv) /* The pidfile may not have been written yet - give it some time */ if (get_pid (pidfile, true) == -1) { alive = true; - retestpid = true; } else { - retestpid = false; + nloopsp = 0; if (do_stop (NULL, NULL, pidfile, uid, 0, true, false, true) > 0) alive = true; @@ -1022,12 +1030,6 @@ int start_stop_daemon (int argc, char **argv) if (! alive) eerrorx ("%s: %s died", applet, exec); } - - if (retestpid) { - if (do_stop (NULL, NULL, pidfile, uid, 0, true, - false, true) < 1) - eerrorx ("%s: %s died", applet, exec); - } } if (svcname) -- cgit v1.2.3