]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
scope: slightly simplify scope_enter_running() error handling
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Sep 2023 20:01:29 +0000 (22:01 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 20 Sep 2023 05:01:53 +0000 (13:01 +0800)
src/core/scope.c

index 1bcd4ed84f29ade6770ed4ee6060ec3e91ea212d..1664d49c94b54a90554b007bdc604e1c1e8b0af2 100644 (file)
@@ -449,13 +449,11 @@ static int scope_enter_running(Scope *s) {
         r = unit_attach_pids_to_cgroup(u, u->pids, NULL);
         if (r < 0) {
                 log_unit_warning_errno(u, r, "Failed to add PIDs to scope's control group: %m");
-                scope_enter_dead(s, SCOPE_FAILURE_RESOURCES);
-                return r;
+                goto fail;
         }
         if (r == 0) {
-                log_unit_warning(u, "No PIDs left to attach to the scope's control group, refusing.");
-                scope_enter_dead(s, SCOPE_FAILURE_RESOURCES);
-                return -ECHILD;
+                r = log_unit_warning_errno(u, SYNTHETIC_ERRNO(ECHILD), "No PIDs left to attach to the scope's control group, refusing.");
+                goto fail;
         }
         log_unit_debug(u, "%i %s added to scope's control group.", r, r == 1 ? "process" : "processes");
 
@@ -475,6 +473,10 @@ static int scope_enter_running(Scope *s) {
         /* Start watching the PIDs currently in the scope (legacy hierarchy only) */
         (void) unit_enqueue_rewatch_pids(u);
         return 1;
+
+fail:
+        scope_enter_dead(s, SCOPE_FAILURE_RESOURCES);
+        return r;
 }
 
 static int scope_start(Unit *u) {