diff options
Diffstat (limited to 'toys/lsb')
-rw-r--r-- | toys/lsb/pidof.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c index 7ef54034..51b742fd 100644 --- a/toys/lsb/pidof.c +++ b/toys/lsb/pidof.c @@ -11,11 +11,12 @@ config PIDOF bool "pidof" default y help - usage: pidof [-s] [-o omitpid[,omitpid..]] [NAME]... + usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]... Print the PIDs of all processes with the given names. + -s single shot, only return one pid. - -o omits processes with specified PID + -o omit PID(s) */ #define FOR_pidof @@ -25,21 +26,19 @@ GLOBALS( char *omit; ) -static int print_pid(pid_t pid, char * name) +static int print_pid(pid_t pid, char *name) { char * res; int len; - sprintf(toybuf, "%d", pid); + sprintf(toybuf, "%d", (int)pid); len = strlen(toybuf); // Check omit string - if (toys.optflags & FLAG_o) - { - res = strstr(TT.omit, toybuf); - if (res && (res == TT.omit || res[-1] == ',') && - (res[len] == ',' || res[len] == 0)) return 1; - } + if (TT.omit && (res = strstr(TT.omit, toybuf))) + if ((res == TT.omit || res[-1] == ',') && + (res[len] == ',' || !res[len])) return 0; + xprintf("%*s", len+(!toys.exitval), toybuf); toys.exitval = 0; |