]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: Ignore kernel threads in cg_kill_items()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 Jul 2024 09:53:32 +0000 (11:53 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 Jul 2024 09:53:32 +0000 (11:53 +0200)
Similar to the implementation of cgroup.kill in the kernel, let's
skip kernel threads in cg_kill_items() as trying to kill kernel
threads as an unprivileged process will fail with EPERM and doesn't
do anything when running privileged.

src/basic/cgroup-util.c

index 65fbd09159f4b35d658f0f859955b31764d31b36..c2150c00c6b406d1edb827461690454403eacfdb 100644 (file)
@@ -369,6 +369,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);