pidof: match on full name and basename
busybox doesn't do this, but procps does.
This commit is contained in:
parent
55dd1076fe
commit
5a06a9f7e1
9
pidof.c
9
pidof.c
@ -33,7 +33,7 @@ main(int argc, char *argv[])
|
|||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
struct procstat ps;
|
struct procstat ps;
|
||||||
char cmdline[BUFSIZ], *cmd, *p, *arg = NULL;
|
char cmdline[BUFSIZ], *cmd, *cmdbase = NULL, *p, *arg = NULL;
|
||||||
int i, found = 0;
|
int i, found = 0;
|
||||||
int sflag = 0, oflag = 0;
|
int sflag = 0, oflag = 0;
|
||||||
struct pidentry *pe, *tmp;
|
struct pidentry *pe, *tmp;
|
||||||
@ -83,16 +83,19 @@ main(int argc, char *argv[])
|
|||||||
if (parsecmdline(ps.pid, cmdline,
|
if (parsecmdline(ps.pid, cmdline,
|
||||||
sizeof(cmdline)) < 0) {
|
sizeof(cmdline)) < 0) {
|
||||||
cmd = ps.comm;
|
cmd = ps.comm;
|
||||||
|
cmdbase = cmd;
|
||||||
} else {
|
} else {
|
||||||
if ((p = strchr(cmdline, ' ')))
|
if ((p = strchr(cmdline, ' ')))
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
cmd = basename(cmdline);
|
cmd = cmdline;
|
||||||
|
cmdbase = basename(cmdline);
|
||||||
}
|
}
|
||||||
/* Workaround for login shells */
|
/* Workaround for login shells */
|
||||||
if (cmd[0] == '-')
|
if (cmd[0] == '-')
|
||||||
cmd++;
|
cmd++;
|
||||||
for (i = 0; i < argc; i++) {
|
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);
|
putword(entry->d_name);
|
||||||
found++;
|
found++;
|
||||||
if (sflag)
|
if (sflag)
|
||||||
|
Loading…
Reference in New Issue
Block a user