From 5a06a9f7e1fa161563d285cb7caf0ae8f530ab7c Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 5 Jul 2014 12:50:18 +0000 Subject: [PATCH] pidof: match on full name and basename busybox doesn't do this, but procps does. --- pidof.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pidof.c b/pidof.c index 5841ed5..c921117 100644 --- a/pidof.c +++ b/pidof.c @@ -33,7 +33,7 @@ main(int argc, char *argv[]) struct dirent *entry; pid_t pid; struct procstat ps; - char cmdline[BUFSIZ], *cmd, *p, *arg = NULL; + char cmdline[BUFSIZ], *cmd, *cmdbase = NULL, *p, *arg = NULL; int i, found = 0; int sflag = 0, oflag = 0; struct pidentry *pe, *tmp; @@ -83,16 +83,19 @@ main(int argc, char *argv[]) if (parsecmdline(ps.pid, cmdline, sizeof(cmdline)) < 0) { cmd = ps.comm; + cmdbase = cmd; } else { if ((p = strchr(cmdline, ' '))) *p = '\0'; - cmd = basename(cmdline); + cmd = cmdline; + cmdbase = basename(cmdline); } /* Workaround for login shells */ if (cmd[0] == '-') cmd++; for (i = 0; i < argc; i++) { - if (strcmp(cmd, argv[i]) == 0) { + if (strcmp(cmd, argv[i]) == 0 || + strcmp(cmdbase, argv[0]) == 0) { putword(entry->d_name); found++; if (sflag)