]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: use RET_GATHER more, return first error
authorMike Yuan <me@yhndnzj.com>
Thu, 19 Oct 2023 12:23:54 +0000 (20:23 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 19 Oct 2023 13:37:33 +0000 (21:37 +0800)
src/basic/cgroup-util.c

index 74aee40f6a5b54ee075d99e326df69ff66ff8432..24a59dd7f5837e690b9d1479e9b8489ad263b06f 100644 (file)
@@ -314,19 +314,17 @@ static int cg_kill_items(
                 done = true;
 
                 r = cg_enumerate_items(SYSTEMD_CGROUP_CONTROLLER, path, &f, item);
-                if (r < 0) {
-                        if (ret >= 0 && r != -ENOENT)
-                                return r;
-
-                        return ret;
-                }
+                if (r == -ENOENT)
+                        break;
+                if (r < 0)
+                        return RET_GATHER(ret, r);
 
                 for (;;) {
                         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
 
                         r = cg_read_pidref(f, &pidref);
                         if (r < 0)
-                                return r;
+                                return RET_GATHER(ret, r);
                         if (r == 0)
                                 break;
 
@@ -341,10 +339,9 @@ static int cg_kill_items(
 
                         /* If we haven't killed this process yet, kill it */
                         r = pidref_kill(&pidref, sig);
-                        if (r < 0) {
-                                if (ret >= 0 && r != -ESRCH)
-                                        ret = r;
-                        } else {
+                        if (r < 0 && r != -ESRCH)
+                                RET_GATHER(ret, r);
+                        if (r >= 0) {
                                 if (flags & CGROUP_SIGCONT)
                                         (void) pidref_kill(&pidref, SIGCONT);
 
@@ -359,17 +356,12 @@ static int cg_kill_items(
                         done = false;
 
                         r = set_put(s, PID_TO_PTR(pidref.pid));
-                        if (r < 0) {
-                                if (ret >= 0)
-                                        return r;
-
-                                return ret;
-                        }
+                        if (r < 0)
+                                return RET_GATHER(ret, r);
                 }
 
-                /* To avoid racing against processes which fork
-                 * quicker than we can kill them we repeat this until
-                 * no new pids need to be killed. */
+                /* To avoid racing against processes which fork quicker than we can kill them, we repeat this
+                 * until no new pids need to be killed. */
 
         } while (!done);