diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-10-19 14:23:54 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-10-19 15:37:33 +0200 |
commit | f65a40fb0b92e0e487e4a94b125a3db6781f1f52 (patch) | |
tree | 4277b9f46ca41efeea9499b8b616779e4a5cc9fc /src | |
parent | core/exec-invoke: use correct exit status (diff) | |
download | systemd-f65a40fb0b92e0e487e4a94b125a3db6781f1f52.tar.xz systemd-f65a40fb0b92e0e487e4a94b125a3db6781f1f52.zip |
cgroup-util: use RET_GATHER more, return first error
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/cgroup-util.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 74aee40f6a..24a59dd7f5 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -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); |