[lxc-devel] [lxc/master] lxccontainer: restore blocking wait()

brauner on Github lxc-bot at linuxcontainers.org
Wed Jan 17 14:24:37 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 404 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180117/51a85b8c/attachment.bin>
-------------- next part --------------
From 8193dd662f178756d950e73441742d321dd16716 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
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 <christian.brauner at ubuntu.com>
---
 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;
 


More information about the lxc-devel mailing list