# HG changeset patch # User Rob Landley # Date 1387237285 21600 # Node ID 1e4e707fc0bc2bfa18f81825a64365d8ffef337e # Parent 37cbbbe547a3c1cfb01a2e88a0e99b80a9829a6b Fix pidof -o bug aborting output, reported by Ashwini Sharma. diff -r 37cbbbe547a3 -r 1e4e707fc0bc toys/lsb/pidof.c --- a/toys/lsb/pidof.c Sun Dec 08 13:26:05 2013 -0600 +++ b/toys/lsb/pidof.c Mon Dec 16 17:41:25 2013 -0600 @@ -11,11 +11,12 @@ 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 @@ 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;