pidof: support "pidof /path/to/binary" case
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 15 Jun 2019 16:35:39 +0000 (18:35 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 15 Jun 2019 16:35:39 +0000 (18:35 +0200)
function                                             old     new   delta
find_pid_by_name                                     230     227      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/find_pid_by_name.c

index abbf293e8863bd43c0b19402aaf3bf59dff7d407..fe13f7211d1beced410f89c69cf1ae9caf488bfd 100644 (file)
@@ -90,7 +90,11 @@ pid_t* FAST_FUNC find_pid_by_name(const char *procName)
                /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/
                 || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0)
                /* or we require /proc/PID/exe link to match */
-                || (p->exe && strcmp(bb_basename(p->exe), procName) == 0)
+                || (p->exe && strcmp(
+                                       procName[0] == '/' ? p->exe /* support "pidof /path/to/binary" case too */
+                                                       : bb_basename(p->exe),
+                                       procName
+                                       ) == 0)
                ) {
                        pidList = xrealloc_vector(pidList, 2, i);
                        pidList[i++] = p->pid;