aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb/pidof.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-12-16 17:41:25 -0600
committerRob Landley <rob@landley.net>2013-12-16 17:41:25 -0600
commit4f20b9628bff272c504b6bf2c7c71619f7337022 (patch)
treeb8ef852e5ee76e19d155c9e471900c0d2d9c0885 /toys/lsb/pidof.c
parentdbbd3d6e485d6a063dcd2f163313b52ce95b42f5 (diff)
downloadtoybox-4f20b9628bff272c504b6bf2c7c71619f7337022.tar.gz
Fix pidof -o bug aborting output, reported by Ashwini Sharma.
Diffstat (limited to 'toys/lsb/pidof.c')
-rw-r--r--toys/lsb/pidof.c19
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;