]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
scope: refuse activation of scopes if no PIDs to add are left 21163/head
authorLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2021 21:17:50 +0000 (23:17 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2021 21:17:50 +0000 (23:17 +0200)
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

src/core/cgroup.c
src/core/scope.c

index 98672c26e288c0a09dd03705fa7142400f912221..abc30e3990c4827d9ad4aa13d12055d3a79b0adc 100644 (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)
index 74f16233c5894a3b7c2f3ed7a50e40ee01eba6f7..63d3288caf16fc8bb3960b8d94d9498f84a6b480 100644 (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;