commit:     eca4357892315ca7340bbfc2b373d7660a34142f
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Sat Oct  6 17:51:04 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sat Oct  6 17:51:04 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=eca43578

supervise-daemon: use nanosleep() instead of sleep()

We will be using sigalrm in this process for health checking, and
sigalrm cannot be used with sleep() safely.

 src/rc/supervise-daemon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 8d56b8d4..24cc56fa 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -425,6 +425,7 @@ static void supervisor(char *exec, char **argv)
        FILE *fp;
        int i;
        int nkilled;
+       struct timespec ts;
        time_t respawn_now= 0;
        time_t first_spawn= 0;
 
@@ -497,7 +498,9 @@ static void supervisor(char *exec, char **argv)
                        if (nkilled > 0)
                                syslog(LOG_INFO, "killed %d processes", 
nkilled);
                } else {
-                       sleep(respawn_delay);
+                       ts.tv_sec = respawn_delay;
+                       ts.tv_nsec = 0;
+                       nanosleep(&ts, NULL);
                        if (respawn_max > 0 && respawn_period > 0) {
                                respawn_now = time(NULL);
                                if (first_spawn == 0)

Reply via email to