summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-07-31 19:07:35 +0200
committerGitHub <noreply@github.com>2024-07-31 19:07:35 +0200
commitff5662129a15b710e592e2784fc11840e2a439b6 (patch)
treef6ea410ddc0e1a2721043b8fb25e84a7337655c8
parentMerge pull request #33873 from DaanDeMeyer/rename-creds (diff)
parentcgroup-util: Don't try to open pidfd for kernel threads (diff)
downloadsystemd-ff5662129a15b710e592e2784fc11840e2a439b6.tar.xz
systemd-ff5662129a15b710e592e2784fc11840e2a439b6.zip
Merge pull request #33885 from DaanDeMeyer/pidref-kthread
Two pidfd fixes
-rw-r--r--src/basic/cgroup-util.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 65fbd09159..ffce7504f4 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -149,7 +149,9 @@ int cg_read_pidref(FILE *f, PidRef *ret, CGroupFlags flags) {
if (pid == 0)
return -EREMOTE;
- if (FLAGS_SET(flags, CGROUP_NO_PIDFD)) {
+ /* We might read kernel thread pids from cgroup.procs for which we cannot create a pidfd so
+ * catch those and don't try to create a pidfd for them. */
+ if (FLAGS_SET(flags, CGROUP_NO_PIDFD) || pid_is_kernel_thread(pid) > 0) {
*ret = PIDREF_MAKE_FROM_PID(pid);
return 1;
}
@@ -369,6 +371,12 @@ static int cg_kill_items(
if (set_get(s, PID_TO_PTR(pidref.pid)) == PID_TO_PTR(pidref.pid))
continue;
+ /* Ignore kernel threads to mimick the behavior of cgroup.kill. */
+ if (pidref_is_kernel_thread(&pidref) > 0) {
+ log_debug("Ignoring kernel thread with pid " PID_FMT " in cgroup '%s'", pidref.pid, path);
+ continue;
+ }
+
if (log_kill)
ret_log_kill = log_kill(&pidref, sig, userdata);