[PATCH] killall5: return 2 if no processes got killed

Uros Vampl mobile.leecher at gmail.com
Fri Dec 13 18:40:29 UTC 2013


This matches killall5 from sysvinit. From its manpage:

EXIT STATUS
       The program return zero if it killed processes. It return 2 if
       no process were killed, and 1 if it was unable to find any 
       processes (/proc/ is missing).

For this to work kernel processes need to be filtered out, this patch 
does that as well


diff -ur busybox.orig/procps/kill.c busybox/procps/kill.c
--- busybox.orig/procps/kill.c	2012-07-18 17:32:32.000000000 +0200
+++ busybox/procps/kill.c	2012-08-12 15:11:35.792678564 +0200
@@ -158,7 +158,7 @@
 	if (killall5) {
 		pid_t sid;
 		procps_status_t* p = NULL;
-		int ret = 0;
+		int ret = 2;
 
 		/* Find out our session id */
 		sid = getsid(pid);
@@ -172,6 +172,7 @@
 			if (p->sid == (unsigned)sid
 			 || p->pid == (unsigned)pid
 			 || p->pid == 1
+			 || p->sid == 0
 			) {
 				continue;
 			}
@@ -200,6 +201,7 @@
 					goto dont_kill;
 			}
 			kill(p->pid, signo);
+			ret = 0;
  dont_kill: ;
 		}
  resume:



More information about the busybox mailing list