]> git.proxmox.com Git - mirror_lxc.git/commitdiff
finalize handler in lxcapi_restore
authorTycho Andersen <tycho.andersen@canonical.com>
Tue, 2 Sep 2014 23:37:05 +0000 (18:37 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 19 Sep 2014 21:00:21 +0000 (17:00 -0400)
We can also narrow the scope of this, since we only need it in the process that
is actually going to use it.

Reported-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxccontainer.c
src/lxc/start.c
src/lxc/start.h

index cbe58ee08a8ed1af550012ffed4e3e53c2116b9c..b8b367ddd62c041b7da67839027f9455bfa9403d 100644 (file)
@@ -3816,12 +3816,6 @@ static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbos
        if (!tmpnam(pidfile))
                return false;
 
-       struct lxc_handler *handler;
-
-       handler = lxc_init(c->name, c->lxc_conf, c->config_path);
-       if (!handler)
-               return false;
-
        pid = fork();
        if (pid < 0)
                return false;
@@ -3863,6 +3857,9 @@ static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbos
                exit(1);
        } else {
                int status;
+               struct lxc_handler *handler;
+               bool error = false;
+
                pid_t w = waitpid(pid, &status, 0);
 
                if (w == -1) {
@@ -3870,29 +3867,37 @@ static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbos
                        return false;
                }
 
+               handler = lxc_init(c->name, c->lxc_conf, c->config_path);
+               if (!handler)
+                       return false;
+
                if (WIFEXITED(status)) {
                        if (WEXITSTATUS(status)) {
-                               return false;
+                               error = true;
+                               goto out_fini_handler;
                        }
                        else {
                                int netnr = 0, ret;
-                               bool error = false;
                                FILE *f = fopen(pidfile, "r");
                                if (!f) {
+                                       error = true;
                                        perror("reading pidfile");
                                        ERROR("couldn't read restore's init pidfile %s\n", pidfile);
-                                       return false;
+                                       goto out_fini_handler;
                                }
 
                                ret = fscanf(f, "%d", (int*) &handler->pid);
                                fclose(f);
                                if (ret != 1) {
+                                       error = true;
                                        ERROR("reading restore pid failed");
-                                       return false;
+                                       goto out_fini_handler;
                                }
 
-                               if (container_mem_lock(c))
-                                       return false;
+                               if (container_mem_lock(c)) {
+                                       error = true;
+                                       goto out_fini_handler;
+                               }
 
                                lxc_list_for_each(it, &c->lxc_conf->network) {
                                        char eth[128], veth[128];
@@ -3916,10 +3921,12 @@ static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbos
 out_unlock:
                                container_mem_unlock(c);
                                if (error)
-                                       return false;
+                                       goto out_fini_handler;
 
-                               if (lxc_set_state(c->name, handler, RUNNING))
-                                       return false;
+                               if (lxc_set_state(c->name, handler, RUNNING)) {
+                                       error = true;
+                                       goto out_fini_handler;
+                               }
                        }
                }
 
@@ -3927,9 +3934,11 @@ out_unlock:
                        lxc_abort(c->name, handler);
                        return false;
                }
-       }
 
-       return true;
+out_fini_handler:
+               lxc_fini(c->name, handler);
+               return !error;
+       }
 }
 
 static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...)
index d9fbc8c40d974abdb9d3b28f82b24ffa03ebad64..f0a3d30996fab1331afc43209fc34c1070535253 100644 (file)
@@ -460,7 +460,7 @@ out_free:
        return NULL;
 }
 
-static void lxc_fini(const char *name, struct lxc_handler *handler)
+void lxc_fini(const char *name, struct lxc_handler *handler)
 {
        /* The STOPPING state is there for future cleanup code
         * which can take awhile
index 8af0a0607fe75bf19a6e554a6efaf4570628fe46..7c75b16f3c1494b3d6688c74d6923304a2b498f4 100644 (file)
@@ -79,6 +79,7 @@ extern int lxc_poll(const char *name, struct lxc_handler *handler);
 extern int lxc_set_state(const char *name, struct lxc_handler *handler, lxc_state_t state);
 extern void lxc_abort(const char *name, struct lxc_handler *handler);
 extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *, const char *);
+extern void lxc_fini(const char *name, struct lxc_handler *handler);
 
 extern int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore);
 int __lxc_start(const char *, struct lxc_conf *, struct lxc_operations *,