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(+)
From 800d66aeeca2cddffb902d1858789638b96ae93b Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
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.33.0.259.gc128427fd7-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to