]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
state: s/sleep()/nanosleep()/ 2531/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 15 Aug 2018 22:39:50 +0000 (00:39 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 15 Aug 2018 22:43:19 +0000 (00:43 +0200)
sleep() is not thread-safe but nanosleep() is. Since no resources are allocated
in lxc_wait() it is safe to call nanosleep() without cancellation handlers.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/state.c

index 5afce9a6a8cdc523ab41b540d0bf6637718031ed..d8a8dab2599abc6885d27da8f783aa7c2ba2251e 100644 (file)
@@ -100,8 +100,8 @@ static int fillwaitedstates(const char *strstates, lxc_state_t *states)
        return 0;
 }
 
-extern int lxc_wait(const char *lxcname, const char *states, int timeout,
-                   const char *lxcpath)
+int lxc_wait(const char *lxcname, const char *states, int timeout,
+            const char *lxcpath)
 {
        int state = -1;
        lxc_state_t s[MAX_STATE] = {0};
@@ -110,6 +110,11 @@ extern int lxc_wait(const char *lxcname, const char *states, int timeout,
                return -1;
 
        for (;;) {
+               struct timespec onesec = {
+                   .tv_sec = 1,
+                   .tv_nsec = 0,
+               };
+
                state = lxc_cmd_sock_get_state(lxcname, lxcpath, s, timeout);
                if (state >= 0)
                        break;
@@ -125,7 +130,7 @@ extern int lxc_wait(const char *lxcname, const char *states, int timeout,
                if (timeout == 0)
                        return -1;
 
-               sleep(1);
+               (void)nanosleep(&onesec, NULL);
        }
 
        if (state < 0) {