supervise-daemon: code cleanup

Clean up the process for killing an active supervisor when stopping.
This commit is contained in:
William Hubbs 2017-09-18 12:25:37 -05:00
parent 0eb47b9af3
commit 3cf19b0f30

View File

@ -432,6 +432,7 @@ int main(int argc, char **argv)
int respawn_period = 5; int respawn_period = 5;
time_t respawn_now= 0; time_t respawn_now= 0;
time_t first_spawn= 0; time_t first_spawn= 0;
struct timespec ts;
struct passwd *pw; struct passwd *pw;
struct group *gr; struct group *gr;
FILE *fp; FILE *fp;
@ -658,17 +659,18 @@ int main(int argc, char **argv)
if (stop) { if (stop) {
pid = get_pid(applet, pidfile); pid = get_pid(applet, pidfile);
if (pid == -1) if (pid != -1) {
i = pid;
else
i = kill(pid, SIGTERM); i = kill(pid, SIGTERM);
if (i != 0) if (i != 0)
/* We failed to send the signal */ /* We failed to send the signal */
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* wait for the supervisor to go down */ /* wait for the supervisor to go down */
while (kill(pid, 0) == 0) while (kill(pid, 0) == 0)
sleep(1); ts.tv_sec = 0;
ts.tv_nsec = 1;
nanosleep(&ts, NULL);
}
/* Even if we have not actually killed anything, we should /* Even if we have not actually killed anything, we should
* remove information about it as it may have unexpectedly * remove information about it as it may have unexpectedly