From f577e0613c7cf3d15ec479aec184b611f4ad46ac Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 17 Jan 2018 15:22:36 +0100 Subject: [PATCH] lxccontainer: restore blocking wait() Closes #2027. Closes lxc/go-lxc#98. Signed-off-by: Christian Brauner --- src/lxc/commands.c | 3 ++- src/lxc/state.c | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 8ce658363..814ce88c1 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -859,7 +859,8 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath, return STOPPED; if (ret < 0) { - ERROR("%s - Failed to execute command", strerror(errno)); + if (errno != ECONNREFUSED) + ERROR("%s - Failed to execute command", strerror(errno)); return -1; } diff --git a/src/lxc/state.c b/src/lxc/state.c index 9c9bf8318..13b99d8ff 100644 --- a/src/lxc/state.c +++ b/src/lxc/state.c @@ -115,13 +115,26 @@ extern int lxc_wait(const char *lxcname, const char *states, int timeout, if (fillwaitedstates(states, s)) return -1; - state = lxc_cmd_sock_get_state(lxcname, lxcpath, s, timeout); - if (state < 0) { - SYSERROR("failed to receive state from monitor"); - return -1; + for (;;) { + state = lxc_cmd_sock_get_state(lxcname, lxcpath, s, timeout); + if (state >= 0) + break; + + if (errno != ECONNREFUSED) { + SYSERROR("Failed to receive state from monitor"); + return -1; + } + + sleep(1); + + if (timeout > 0) + timeout--; + + if (timeout == 0) + return -1; } - TRACE("retrieved state of container %s", lxc_state2str(state)); + TRACE("Retrieved state of container %s", lxc_state2str(state)); if (!s[state]) return -1; -- 2.47.2