state: s/sleep()/nanosleep()/

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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 4cb8ca34
......@@ -100,7 +100,7 @@ static int fillwaitedstates(const char *strstates, lxc_state_t *states)
return 0;
}
extern int lxc_wait(const char *lxcname, const char *states, int timeout,
int lxc_wait(const char *lxcname, const char *states, int timeout,
const char *lxcpath)
{
int state = -1;
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment