1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 07:51:21 +03:00

scope: refuse activation of scopes if no PIDs to add are left

If all processes we are supposed to add are gone by the time we are
ready to do so, let's fail.

THis is heavily based on Cunlong Li's work, who thankfully tracked this
down.

Replaces: #20577
This commit is contained in:
Lennart Poettering 2021-10-27 23:17:50 +02:00
parent db4229d12f
commit 8d3e4ac7cd
2 changed files with 8 additions and 1 deletions

View File

@ -2291,7 +2291,8 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
ret = r; /* Remember first error */
continue;
}
} else if (ret >= 0)
ret++; /* Count successful additions */
r = cg_all_unified();
if (r < 0)

View File

@ -391,6 +391,12 @@ static int scope_start(Unit *u) {
scope_enter_dead(s, SCOPE_FAILURE_RESOURCES);
return r;
}
if (r == 0) {
log_unit_warning(u, "No PIDs left to attach to the scope's control group, refusing: %m");
scope_enter_dead(s, SCOPE_FAILURE_RESOURCES);
return -ECHILD;
}
log_unit_debug(u, "%i %s added to scope's control group.", r, r == 1 ? "process" : "processes");
s->result = SCOPE_SUCCESS;