]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxccontainer: cleanup + bugfixes
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 11 Jun 2017 04:33:06 +0000 (06:33 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 13 Jun 2017 04:13:20 +0000 (06:13 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c

index ad35605a46ea735ff1470a099b36b8926f724923..e74a0266a3f642afa8ad129a406904519ed2b252 100644 (file)
@@ -737,17 +737,17 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
        if (!c->lxc_conf)
                return false;
 
-       if ((ret = ongoing_create(c)) < 0) {
+       ret = ongoing_create(c);
+       if (ret < 0) {
                ERROR("Error checking for incomplete creation");
                return false;
-       }
-       if (ret == 2) {
-               ERROR("Error: %s creation was not completed", c->name);
-               do_lxcapi_destroy(c);
-               return false;
        } else if (ret == 1) {
                ERROR("Error: creation of %s is ongoing", c->name);
                return false;
+       } else if (ret == 2) {
+               ERROR("Error: %s creation was not completed", c->name);
+               do_lxcapi_destroy(c);
+               return false;
        }
 
        /* is this app meant to be run through lxcinit, as in lxc-execute? */
@@ -790,9 +790,11 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
        */
        if (daemonize) {
                char title[2048];
+               pid_t pid;
 
-               pid_t pid = fork();
+               pid = fork();
                if (pid < 0) {
+                       free_init_cmd(init_cmd);
                        lxc_free_handler(handler);
                        return false;
                }
@@ -849,6 +851,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
                if (pid_fp == NULL) {
                        SYSERROR("Failed to create pidfile '%s' for '%s'",
                                 c->pidfile, c->name);
+                       free_init_cmd(init_cmd);
                        lxc_free_handler(handler);
                        if (daemonize)
                                exit(1);
@@ -859,6 +862,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
                        SYSERROR("Failed to write '%s'", c->pidfile);
                        fclose(pid_fp);
                        pid_fp = NULL;
+                       free_init_cmd(init_cmd);
                        lxc_free_handler(handler);
                        if (daemonize)
                                exit(1);
@@ -875,11 +879,13 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
        if (conf->monitor_unshare) {
                if (unshare(CLONE_NEWNS)) {
                        SYSERROR("failed to unshare mount namespace");
+                       free_init_cmd(init_cmd);
                        lxc_free_handler(handler);
                        return false;
                }
                if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL)) {
                        SYSERROR("Failed to make / rslave at startup");
+                       free_init_cmd(init_cmd);
                        lxc_free_handler(handler);
                        return false;
                }