From 4f20b9628bff272c504b6bf2c7c71619f7337022 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 16 Dec 2013 17:41:25 -0600 Subject: Fix pidof -o bug aborting output, reported by Ashwini Sharma. --- toys/lsb/pidof.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'toys/lsb/pidof.c') 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; -- cgit v1.2.3