]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
When starting a container daemonized, wait for it to reach RUNNING state before retur...
authorStéphane Graber <stgraber@ubuntu.com>
Mon, 27 Aug 2012 23:01:36 +0000 (19:01 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 12 Nov 2012 18:16:16 +0000 (13:16 -0500)
If the container doesn't reach RUNNING state in 5 seconds, a failure will be
returned to the user.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxccontainer.c

index f61ba0060ca809956757d7c7a4ee84b389832076..e88460b8648e9c4be2e4e106cd5d9b4779cc83f5 100644 (file)
@@ -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;