Blame SOURCES/procps-ng-3.3.15-pidof-kernel-workers-option.patch

13bf06
From d9b3415d2a761cb7669a67f5309665335d5eb4c4 Mon Sep 17 00:00:00 2001
13bf06
From: rpm-build <rpm-build>
13bf06
Date: Mon, 9 Nov 2020 16:10:22 +0100
13bf06
Subject: [PATCH] New '-w' option for kernel workers.
13bf06
13bf06
---
13bf06
 pidof.1 |  3 +++
13bf06
 pidof.c | 17 ++++++++++++-----
13bf06
 2 files changed, 15 insertions(+), 5 deletions(-)
13bf06
13bf06
diff --git a/pidof.1 b/pidof.1
13bf06
index 1368704..c85c088 100644
13bf06
--- a/pidof.1
13bf06
+++ b/pidof.1
13bf06
@@ -45,6 +45,9 @@ the current root directory of processes they do not own.
13bf06
 .IP \-x
13bf06
 Scripts too - this causes the program to also return process id's of
13bf06
 shells running the named scripts.
13bf06
+.IP \-w
13bf06
+Show also processes that do not have visible command line (e.g. kernel
13bf06
+worker threads).
13bf06
 .IP "-o \fIomitpid\fP"
13bf06
 Tells \fIpidof\fP to omit processes with that process id. The special
13bf06
 pid \fB%PPID\fP can be used to name the parent process of the \fIpidof\fP
13bf06
diff --git a/pidof.c b/pidof.c
13bf06
index 94e19bb..7fdf27a 100644
13bf06
--- a/pidof.c
13bf06
+++ b/pidof.c
13bf06
@@ -55,6 +55,8 @@ static char *program = NULL;
13bf06
 static int opt_single_shot    = 0;  /* -s */
13bf06
 static int opt_scripts_too    = 0;  /* -x */
13bf06
 static int opt_rootdir_check  = 0;  /* -c */
13bf06
+static int opt_with_workers   = 0;  /* -w */
13bf06
+
13bf06
 
13bf06
 static char *pidof_root = NULL;
13bf06
 
13bf06
@@ -69,6 +71,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
13bf06
 	fputs(_(" -s, --single-shot         return one PID only\n"), fp);
13bf06
 	fputs(_(" -c, --check-root          omit processes with different root\n"), fp);
13bf06
 	fputs(_(" -x                        also find shells running the named scripts\n"), fp);
13bf06
+	fputs(_(" -w, --with-workers        show kernel workers too\n"), fp);
13bf06
 	fputs(_(" -o, --omit-pid <PID,...>  omit processes with PID\n"), fp);
13bf06
 	fputs(_(" -S, --separator SEP       use SEP as separator put between PIDs"), fp);
13bf06
 	fputs(USAGE_SEPARATOR, fp);
13bf06
@@ -142,7 +145,6 @@ static void select_procs (void)
13bf06
 	static int size = 0;
13bf06
 	char *cmd_arg0, *cmd_arg0base;
13bf06
 	char *cmd_arg1, *cmd_arg1base;
13bf06
-	char *stat_cmd;
13bf06
 	char *program_base;
13bf06
 	char *root_link;
13bf06
 	char *exe_link;
13bf06
@@ -168,10 +170,9 @@ static void select_procs (void)
13bf06
 			}
13bf06
 		}
13bf06
 
13bf06
-		if (!is_omitted(task.XXXID)) {
13bf06
+		if (!is_omitted(task.XXXID) && ((task.cmdline && *task.cmdline) || opt_with_workers)) {
13bf06
 
13bf06
 			cmd_arg0 = (task.cmdline && *task.cmdline) ? *task.cmdline : "\0";
13bf06
-			stat_cmd = task.cmd ? task.cmd : "\0";
13bf06
 
13bf06
 			/* processes starting with '-' are login shells */
13bf06
 			if (*cmd_arg0 == '-') {
13bf06
@@ -193,7 +194,7 @@ static void select_procs (void)
13bf06
 			    !strcmp(program_base, cmd_arg0) ||
13bf06
 			    !strcmp(program, cmd_arg0) ||
13bf06
 
13bf06
-			    !strcmp(program, stat_cmd) ||
13bf06
+			    (opt_with_workers && !strcmp(program, task.cmd)) ||
13bf06
 
13bf06
 			    !strcmp(program, exe_link_base) ||
13bf06
 			    !strcmp(program, exe_link))
13bf06
@@ -293,13 +294,14 @@ int main (int argc, char **argv)
13bf06
 	int first_pid = 1;
13bf06
 
13bf06
 	const char *separator = " ";
13bf06
-	const char *opts = "scnxmo:S:?Vh";
13bf06
+	const char *opts = "scnxwmo:S:?Vh";
13bf06
 
13bf06
 	static const struct option longopts[] = {
13bf06
 		{"check-root", no_argument, NULL, 'c'},
13bf06
 		{"single-shot", no_argument, NULL, 's'},
13bf06
 		{"omit-pid", required_argument, NULL, 'o'},
13bf06
 		{"separator", required_argument, NULL, 's'},
13bf06
+		{"with-workers", no_argument, NULL, 'w'},
13bf06
 		{"help", no_argument, NULL, 'h'},
13bf06
 		{"version", no_argument, NULL, 'V'},
13bf06
 		{NULL, 0, NULL, 0}
13bf06
@@ -325,6 +327,9 @@ int main (int argc, char **argv)
13bf06
 		case 'x':
13bf06
 			opt_scripts_too = 1;
13bf06
 			break;
13bf06
+		case 'w':
13bf06
+			opt_with_workers = 1;
13bf06
+			break;
13bf06
 		case 'c':
13bf06
 			if (geteuid() == 0) {
13bf06
 				opt_rootdir_check = 1;
13bf06
@@ -358,6 +363,8 @@ int main (int argc, char **argv)
13bf06
 
13bf06
 		program = argv[optind++];
13bf06
 
13bf06
+		if (*program == '\0') continue;
13bf06
+
13bf06
 		select_procs();	/* get the list of matching processes */
13bf06
 
13bf06
 		if (proc_count) {
13bf06
-- 
13bf06
2.25.4
13bf06