diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2017-09-18 12:25:37 -0500 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2017-09-18 12:25:37 -0500 |
commit | 3cf19b0f30a90157d23d09ded304439f1eb42d4a (patch) | |
tree | 8dceb2681f396e05aee320459152b0a7d374a006 /src | |
parent | 0eb47b9af340dd07209a3920944ed085fe7bd359 (diff) |
supervise-daemon: code cleanup
Clean up the process for killing an active supervisor when stopping.
Diffstat (limited to 'src')
-rw-r--r-- | src/rc/supervise-daemon.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c index 7b894e7b..2800d1a2 100644 --- a/src/rc/supervise-daemon.c +++ b/src/rc/supervise-daemon.c @@ -432,6 +432,7 @@ int main(int argc, char **argv) int respawn_period = 5; time_t respawn_now= 0; time_t first_spawn= 0; + struct timespec ts; struct passwd *pw; struct group *gr; FILE *fp; @@ -658,17 +659,18 @@ int main(int argc, char **argv) if (stop) { pid = get_pid(applet, pidfile); - if (pid == -1) - i = pid; - else + if (pid != -1) { i = kill(pid, SIGTERM); - if (i != 0) - /* We failed to send the signal */ - exit(EXIT_FAILURE); - - /* wait for the supervisor to go down */ - while (kill(pid, 0) == 0) - sleep(1); + if (i != 0) + /* We failed to send the signal */ + exit(EXIT_FAILURE); + + /* wait for the supervisor to go down */ + while (kill(pid, 0) == 0) + ts.tv_sec = 0; + ts.tv_nsec = 1; + nanosleep(&ts, NULL); + } /* Even if we have not actually killed anything, we should * remove information about it as it may have unexpectedly |