From: Stéphane Graber Date: Mon, 27 Aug 2012 23:01:36 +0000 (-0400) Subject: When starting a container daemonized, wait for it to reach RUNNING state before retur... X-Git-Tag: lxc-0.9.0.alpha1~1^2~155 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a44c8b447c4cac2b71bf842a61440bae9caf918;p=thirdparty%2Flxc.git When starting a container daemonized, wait for it to reach RUNNING state before returning the result of start(). 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 --- 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;