Commit 7a44c8b4 by Stéphane Graber

When starting a container daemonized, wait for it to reach RUNNING state before…

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 72d0e1cb
...@@ -244,6 +244,26 @@ static void lxcapi_want_daemonize(struct lxc_container *c) ...@@ -244,6 +244,26 @@ static void lxcapi_want_daemonize(struct lxc_container *c)
c->daemonize = 1; 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 '...', * 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) * 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) ...@@ -298,7 +318,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char ** argv)
return false; return false;
} }
if (pid != 0) if (pid != 0)
return true; return wait_on_daemonized_start(c);
/* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */ /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */
chdir("/"); chdir("/");
close(0); close(0);
...@@ -408,17 +428,6 @@ static bool lxcapi_stop(struct lxc_container *c) ...@@ -408,17 +428,6 @@ static bool lxcapi_stop(struct lxc_container *c)
return ret == 0; 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) static bool valid_template(char *t)
{ {
struct stat statbuf; struct stat statbuf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment