]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
killall: use is_kernel_thread() during killing spree process filtering too
authorLennart Poettering <lennart@poettering.net>
Mon, 24 Sep 2018 17:03:17 +0000 (19:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 Sep 2018 10:50:35 +0000 (12:50 +0200)
Apparently the new "bpfilter" subsystem otherwise confuses us.

See: https://lists.freedesktop.org/archives/systemd-devel/2018-September/041392.html

src/core/killall.c

index 87d207fd3d1382577381f1ef4aa37a60af298924..3dde3033fa3b97773cf9b1e40936f5d5547fdf7e 100644 (file)
@@ -23,9 +23,8 @@
 
 static bool ignore_proc(pid_t pid, bool warn_rootfs) {
         _cleanup_fclose_ FILE *f = NULL;
-        char c;
         const char *p;
-        size_t count;
+        char c = 0;
         uid_t uid;
         int r;
 
@@ -33,6 +32,11 @@ static bool ignore_proc(pid_t pid, bool warn_rootfs) {
         if (pid == 1)
                 return true;
 
+        /* Ignore kernel threads */
+        r = is_kernel_thread(pid);
+        if (r != 0)
+                return true; /* also ignore processes where we can't determine this */
+
         r = get_process_uid(pid, &uid);
         if (r < 0)
                 return true; /* not really, but better safe than sorry */
@@ -46,11 +50,10 @@ static bool ignore_proc(pid_t pid, bool warn_rootfs) {
         if (!f)
                 return true; /* not really, but has the desired effect */
 
-        count = fread(&c, 1, 1, f);
-
-        /* Kernel threads have an empty cmdline */
-        if (count <= 0)
-                return true;
+        /* Try to read the first character of the command line. If the cmdline is empty (which might be the case for
+         * kernel threads but potentially also other stuff), this line won't do anything, but we don't care much, as
+         * actual kernel threads are already filtered out above. */
+        (void) fread(&c, 1, 1, f);
 
         /* Processes with argv[0][0] = '@' we ignore from the killing spree.
          *