From: Christian Brauner Date: Sat, 28 Mar 2020 13:56:51 +0000 (+0100) Subject: cgroups: move check for valid monitor process up X-Git-Tag: lxc-5.0.0~483^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c468e4d42902d6f56659ee3b3d9009c5d711337a;p=thirdparty%2Flxc.git cgroups: move check for valid monitor process up Cc: cenxianlong Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 0df850695..68d158aa3 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -1082,6 +1082,12 @@ __cgfsng_ops static void cgfsng_monitor_destroy(struct cgroup_ops *ops, if (!h->monitor_full_path) continue; + /* Monitor might have died before we entered the cgroup. */ + if (handler->monitor_pid <= 0) { + WARN("No valid monitor process found while destroying cgroups"); + goto try_recursive_destroy; + } + if (conf && conf->cgroup_meta.dir) pivot_path = must_make_path(h->mountpoint, h->container_base_path, @@ -1098,12 +1104,10 @@ __cgfsng_ops static void cgfsng_monitor_destroy(struct cgroup_ops *ops, goto try_recursive_destroy; } - if (handler->monitor_pid != 0) { - ret = lxc_write_openat(pivot_path, "cgroup.procs", pidstr, len); - if (ret != 0) { - SYSWARN("Failed to move monitor %s to \"%s\"", pidstr, pivot_path); - continue; - } + ret = lxc_write_openat(pivot_path, "cgroup.procs", pidstr, len); + if (ret != 0) { + SYSWARN("Failed to move monitor %s to \"%s\"", pidstr, pivot_path); + continue; } try_recursive_destroy: