1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-07 21:18:41 +03:00

cgroup-util: Add debug logging for cg_kill_recursive()

This commit is contained in:
Daan De Meyer 2024-05-29 19:48:19 +02:00
parent c15747e4ab
commit 330ecca853

View File

@ -140,7 +140,7 @@ int cg_read_pidref(FILE *f, PidRef *ret, CGroupFlags flags) {
r = cg_read_pid(f, &pid, flags);
if (r < 0)
return r;
return log_debug_errno(r, "Failed to read pid from cgroup item: %m");
if (r == 0) {
*ret = PIDREF_NULL;
return 0;
@ -347,14 +347,14 @@ static int cg_kill_items(
if (r == -ENOENT)
break;
if (r < 0)
return RET_GATHER(ret, r);
return RET_GATHER(ret, log_debug_errno(r, "Failed to enumerate cgroup items: %m"));
for (;;) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
r = cg_read_pidref(f, &pidref, /* flags = */ 0);
if (r < 0)
return RET_GATHER(ret, r);
return RET_GATHER(ret, log_debug_errno(r, "Failed to read pidref from cgroup '%s': %m", path));
if (r == 0)
break;
@ -370,7 +370,7 @@ static int cg_kill_items(
/* If we haven't killed this process yet, kill it */
r = pidref_kill(&pidref, sig);
if (r < 0 && r != -ESRCH)
RET_GATHER(ret, r);
RET_GATHER(ret, log_debug_errno(r, "Failed to kill process with pid " PID_FMT " from cgroup '%s': %m", pidref.pid, path));
if (r >= 0) {
if (flags & CGROUP_SIGCONT)
(void) pidref_kill(&pidref, SIGCONT);
@ -409,6 +409,8 @@ int cg_kill(
int r, ret;
r = cg_kill_items(path, sig, flags, s, log_kill, userdata, "cgroup.procs");
if (r < 0)
log_debug_errno(r, "Failed to kill processes in cgroup '%s' item cgroup.procs: %m", path);
if (r < 0 || sig != SIGKILL)
return r;
@ -425,7 +427,7 @@ int cg_kill(
r = cg_kill_items(path, sig, flags, s, log_kill, userdata, "cgroup.threads");
if (r < 0)
return r;
return log_debug_errno(r, "Failed to kill processes in cgroup '%s' item cgroup.threads: %m", path);
return r > 0 || ret > 0;
}
@ -448,7 +450,7 @@ int cg_kill_kernel_sigkill(const char *path) {
r = write_string_file(killfile, "1", WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
return r;
return log_debug_errno(r, "Failed to write to cgroup.kill for cgroup '%s': %m", path);
return 0;
}
@ -485,7 +487,7 @@ int cg_kill_recursive(
r = cg_enumerate_subgroups(SYSTEMD_CGROUP_CONTROLLER, path, &d);
if (r < 0) {
if (r != -ENOENT)
RET_GATHER(ret, r);
RET_GATHER(ret, log_debug_errno(r, "Failed to enumerate cgroup '%s' subgroups: %m", path));
return ret;
}
@ -495,7 +497,7 @@ int cg_kill_recursive(
r = cg_read_subgroup(d, &fn);
if (r < 0) {
RET_GATHER(ret, r);
RET_GATHER(ret, log_debug_errno(r, "Failed to read subgroup from cgroup '%s': %m", path));
break;
}
if (r == 0)
@ -506,6 +508,8 @@ int cg_kill_recursive(
return -ENOMEM;
r = cg_kill_recursive(p, sig, flags, s, log_kill, userdata);
if (r < 0)
log_debug_errno(r, "Failed to recursively kill processes in cgroup '%s': %m", p);
if (r != 0 && ret >= 0)
ret = r;
}
@ -514,7 +518,7 @@ int cg_kill_recursive(
if (FLAGS_SET(flags, CGROUP_REMOVE)) {
r = cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, path);
if (!IN_SET(r, -ENOENT, -EBUSY))
RET_GATHER(ret, r);
RET_GATHER(ret, log_debug_errno(r, "Failed to remove cgroup '%s': %m", path));
}
return ret;