diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 98672c26e2..abc30e3990 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -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) diff --git a/src/core/scope.c b/src/core/scope.c index 74f16233c5..63d3288caf 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -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;