From: Christian Brauner Date: Wed, 17 Jan 2018 14:22:36 +0000 (+0100) Subject: lxccontainer: restore blocking wait() X-Git-Tag: lxc-2.0.10~407 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba9605d8b009695433712936253022f524d40112;p=thirdparty%2Flxc.git lxccontainer: restore blocking wait() Closes #2027. Closes lxc/go-lxc#98. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index b33958100..d3db288ec 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -850,7 +850,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 97b22a98e..0193b77fa 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;