Skip to content

Commit

Permalink
cgroups: move check for valid monitor process up
Browse files Browse the repository at this point in the history
Cc: cenxianlong <cenxianlong@huawei.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner authored and stgraber committed Mar 28, 2020
1 parent e5da28d commit 16a3be6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 16a3be6

Please sign in to comment.