]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
start: ensure cgroups are cleaned up
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 3 Aug 2017 21:55:23 +0000 (23:55 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 15 Aug 2017 20:38:28 +0000 (16:38 -0400)
When a container is marked as being in STOPPED state it is possible for another
thread to start it again even though not all cleanup operations for that
container have finished. This is not a problem for most things like sockets and
friends which are unique to the container. It is however a problem for cgroups
which are named after that container in that we cause our cgroup driver to
waste cpu cycles finding a new cgroup name.

Closes  #1726.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/start.c

index fd05a10584312705f3a440d01364c56cea22dd3d..19deddb5c350a0c5f9bb228438cffac472192ebd 100644 (file)
@@ -717,8 +717,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
                handler->netnsfd = -1;
        }
 
+       cgroup_destroy(handler);
+
        lxc_set_state(name, handler, STOPPED);
 
+       /* close command socket */
+       close(handler->conf->maincmd_fd);
+       handler->conf->maincmd_fd = -1;
+
        if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) {
                ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", name);
                if (handler->conf->reboot) {
@@ -736,10 +742,6 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
        lxc_console_delete(&handler->conf->console);
        lxc_delete_tty(&handler->conf->tty_info);
 
-       /* close the command socket */
-       close(handler->conf->maincmd_fd);
-       handler->conf->maincmd_fd = -1;
-
        /* The command socket is now closed, no more state clients can register
         * themselves from now on. So free the list of state clients.
         */
@@ -752,7 +754,6 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
                free(cur);
        }
 
-       free(handler->name);
        if (handler->ttysock[0] != -1) {
                close(handler->ttysock[0]);
                close(handler->ttysock[1]);
@@ -761,7 +762,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
        if (handler->conf->ephemeral == 1 && handler->conf->reboot != 1)
                lxc_destroy_container_on_signal(handler, name);
 
-       cgroup_destroy(handler);
+       free(handler->name);
        free(handler);
 }