From 366d5a96b041ebcd71e44249fb1472e27ea0c705 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 26 Aug 2021 17:12:06 -0700 Subject: [PATCH] ps: exit with exit status 1 if no processes shown. This matches procps ps, and at least one LTP test relies on it. The behavior is specifically "nothing matches", not "one PID didn't match": assuming no process 666, `ps 666` exits with 1, but `ps 1 666` exits with 0. --- toys/posix/ps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 304fe006..f8b2e03a 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1400,6 +1400,7 @@ void ps_main(void) if (CFG_TOYBOX_FREE) free(tbsort); } + if (!TT.kcount) toys.exitval = 1; if (CFG_TOYBOX_FREE) { free(TT.gg.ptr); free(TT.GG.ptr); -- 2.39.2