process-util: be more careful in is_kernel_thread()

This reworks is_kernel_thread() a bit. Instead of checking whether
/proc/$pid/cmdline is entirely empty we now parse the 'flags' field from
/proc/$pid/stat and check the PF_KTHREAD flag, which directly encodes
whether something is a kernel thread.

Why all this? With current kernels userspace processes can set their
command line to empty too (through PR_SET_MM_ARG_START and friends), and
could potentially confuse us. Hence, let's use a more reliable way to
detect kernels like this.
This commit is contained in:
Lennart Poettering
2018-02-12 11:34:00 +01:00
parent 004c7f169e
commit 36b5119a0c
2 changed files with 48 additions and 20 deletions
+4
View File
@@ -1355,4 +1355,8 @@ struct fib_rule_uid_range {
#define NS_GET_NSTYPE _IO(0xb7, 0x3)
#endif
#ifndef PF_KTHREAD
#define PF_KTHREAD 0x00200000
#endif
#include "missing_syscall.h"