From 5d2619774ea77b02e4642401fb3c1dbd02253011 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 4 Jun 2016 09:26:14 -0700 Subject: Basic success/failure return from pgrep/pkill. The man page says they also return 2 for syntax errors and 3 for "fatal error: out of memory etc", but I don't know how to implement that and don't need it (or have any reason to believe anyone needs it). Bug: 29092208 --- toys/posix/ps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'toys/posix/ps.c') diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 82a84438..def81c55 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1685,7 +1685,10 @@ static void match_pgrep(struct carveup *tb) if ((toys.optflags&FLAG_v) ? !!reg : !reg) return; } - // Repurpose a field for -c count + // pgrep should return success if there's a match. + toys.exitval = 0; + + // Repurpose a field for -c count. TT.sortpos++; if (toys.optflags&(FLAG_n|FLAG_o)) { long long ll = tb->slot[SLOT_starttime]; @@ -1738,6 +1741,9 @@ void pgrep_main(void) TT.match_process = pgrep_match_process; TT.show_process = (void *)match_pgrep; + // pgrep should return failure if there are no matches. + toys.exitval = 1; + dirtree_read("/proc", get_ps); if (toys.optflags&FLAG_c) printf("%d\n", TT.sortpos); if (TT.pgrep.snapshot) { -- cgit v1.2.3