]> granicus.if.org Git - procps-ng/commitdiff
pidof: check cmd if space in argv0
authorCraig Small <csmall@enc.com.au>
Sun, 17 Apr 2016 06:43:26 +0000 (16:43 +1000)
committerCraig Small <csmall@enc.com.au>
Sun, 17 Apr 2016 06:43:26 +0000 (16:43 +1000)
A difference in behaviour between the sysvinit and procps pidof
was that the procps one would sometimes not find process that
the sysvinit one did.

The difference is that if a space is found in argv[0] then sysvinit
would look at cmd for a match. This isn't perfect and more of a
best guess but does often work.

procps pidof now follows the same "standard". The most obvious
difference is with kde based processes and incoming ssh connections
with sshd.

References:
 GitLab issue #4
 https://gitlab.com/procps-ng/procps/issues/4
 https://github.com/limingth/sysvinit/blob/master/sysvinit-2.88dsf/src/killall5.c#L800

NEWS
pidof.c

diff --git a/NEWS b/NEWS
index c044e61c2d2684b9a0ec146662a72b594614a7e1..d04b42e1c126a554522cca8600d699ccfbc30ede 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ procps-ng-NEXT
   * ps: display control group name with -o cgname
   * ps: Fallback to attr/current for context Debian #786956
   * tests: Conditionally add prctl Debian #816237
+  * pidof: check cmd if space in argv0. GitLab #4
 
 procps-ng-3.3.11
 ----------------
diff --git a/pidof.c b/pidof.c
index 8712d113621522e744b0379cc46af615c19a20a9..01f0c0a1a2ead11b3ad93483d3394d0ad0a19c95 100644 (file)
--- a/pidof.c
+++ b/pidof.c
@@ -210,6 +210,12 @@ static void select_procs (void)
                                        match = 1;
                                }
                        }
+            /* If there is a space in arg0 then process probably has
+             * setproctitle so use the cmdline
+             */
+            if (!match && strchr(cmd_arg0, ' ')) {
+                match = (strcmp(program, task.cmd)==0);
+            }
 
                        safe_free(exe_link);