From 7a44c8b447c4cac2b71bf842a61440bae9caf918 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Graber?= Date: Mon, 27 Aug 2012 19:01:36 -0400 Subject: [PATCH] When starting a container daemonized, wait for it to reach RUNNING state before returning the result of start(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If the container doesn't reach RUNNING state in 5 seconds, a failure will be returned to the user. Signed-off-by: Serge Hallyn Acked-by: Stéphane Graber --- src/lxc/lxccontainer.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index f61ba0060..e88460b86 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -244,6 +244,26 @@ static void lxcapi_want_daemonize(struct lxc_container *c) c->daemonize = 1; } +static bool lxcapi_wait(struct lxc_container *c, char *state, int timeout) +{ + int ret; + + if (!c) + return false; + + ret = lxc_wait(c->name, state, timeout); + return ret == 0; +} + + +static bool wait_on_daemonized_start(struct lxc_container *c) +{ + /* we'll probably want to make this timeout configurable? */ + int timeout = 5; + + return lxcapi_wait(c, "RUNNING", timeout); +} + /* * I can't decide if it'd be more convenient for callers if we accept '...', * or a null-terminated array (i.e. execl vs execv) @@ -298,7 +318,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char ** argv) return false; } if (pid != 0) - return true; + return wait_on_daemonized_start(c); /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */ chdir("/"); close(0); @@ -408,17 +428,6 @@ static bool lxcapi_stop(struct lxc_container *c) return ret == 0; } -static bool lxcapi_wait(struct lxc_container *c, char *state, int timeout) -{ - int ret; - - if (!c) - return false; - - ret = lxc_wait(c->name, state, timeout); - return ret == 0; -} - static bool valid_template(char *t) { struct stat statbuf; -- 2.47.2