From 3fed6c510fa597be32327e3e5aa2beb43a025553 Mon Sep 17 00:00:00 2001 From: LiFeng Date: Wed, 27 Nov 2019 22:33:46 -0500 Subject: [PATCH 124/139] lxc: close maincmd fd before destroy cgroup Signed-off-by: LiFeng --- src/lxc/cgroups/cgfsng.c | 6 ++++-- src/lxc/start.c | 33 ++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 87b49b0..c96285e 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -2013,8 +2013,10 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops, const char *name, path = lxc_cmd_get_cgroup_path(name, lxcpath, h->controllers[0]); /* not running */ - if (path == NULL) - return false; + if (path == NULL) { + ERROR("Failed to attach %d to cgroup of %s", (int)pid, name); + return false; + } fullpath = build_full_cgpath_from_monitorpath(h, path, "cgroup.procs"); free(path); diff --git a/src/lxc/start.c b/src/lxc/start.c index 7246283..63be4e3 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1185,19 +1185,6 @@ void lxc_fini(const char *name, struct lxc_handler *handler) while (namespace_count--) free(namespaces[namespace_count]); -retry: - if (!cgroup_ops->destroy(cgroup_ops, handler)) { - TRACE("Trying to kill all subprocess"); - signal_all_processes(handler); - TRACE("Finished kill all subprocess"); - if (retry_count < max_retry) { - usleep(100 * 1000); /* 100 millisecond */ - retry_count++; - goto retry; - } - SYSERROR("Failed to destroy cgroup path for container: \"%s\"", handler->name); - } - if (handler->conf->reboot == REBOOT_NONE) { /* For all new state clients simply close the command socket. * This will inform all state clients that the container is @@ -1208,13 +1195,27 @@ retry: lxc_abstract_unix_close(handler->conf->maincmd_fd); handler->conf->maincmd_fd = -1; TRACE("Closed command socket"); + } +retry: + if (!cgroup_ops->destroy(cgroup_ops, handler)) { + TRACE("Trying to kill all subprocess"); + signal_all_processes(handler); + TRACE("Finished kill all subprocess"); + if (retry_count < max_retry) { + usleep(100 * 1000); /* 100 millisecond */ + retry_count++; + goto retry; + } + SYSERROR("Failed to destroy cgroup path for container: \"%s\"", handler->name); + } + + if (handler->conf->reboot == REBOOT_NONE) { /* This function will try to connect to the legacy lxc-monitord * state server and only exists for backwards compatibility. */ lxc_monitor_send_state(name, STOPPED, handler->lxcpath); - /* isuald: write exit code to exit fifo */ if (handler->conf->exit_fd >= 0) { ret = write(handler->conf->exit_fd, &handler->exit_code, sizeof(int)); @@ -2848,7 +2849,6 @@ int do_lxcapi_clean_resource(char *name, char *lxcpath, struct lxc_conf *conf, p ret = -1; goto out; } - signal_all_processes(handler); if (run_oci_hooks(handler->name, "oci-poststop", handler->conf, handler->lxcpath)) { ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", handler->name); @@ -2857,6 +2857,9 @@ int do_lxcapi_clean_resource(char *name, char *lxcpath, struct lxc_conf *conf, p retry: if (!handler->cgroup_ops->destroy(handler->cgroup_ops, handler)) { + TRACE("Trying to kill all subprocess"); + signal_all_processes(handler); + TRACE("Finished kill all subprocess"); if (retry_count < max_retry) { usleep(100 * 1000); /* 100 millisecond */ retry_count++; -- 1.8.3.1