commit:     3cf19b0f30a90157d23d09ded304439f1eb42d4a
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Mon Sep 18 17:25:37 2017 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon Sep 18 17:25:37 2017 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3cf19b0f

supervise-daemon: code cleanup

Clean up the process for killing an active supervisor when stopping.

 src/rc/supervise-daemon.c | 22 ++++++++++++----------
 1 file 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

Reply via email to