svn commit: trunk/busybox: include procps

vda at busybox.net vda at busybox.net
Sat Feb 7 22:30:40 UTC 2009


Author: vda
Date: 2009-02-07 22:30:39 +0000 (Sat, 07 Feb 2009)
New Revision: 25261

Log:
function                                             old     new   delta
kill_main                                            706     884    +178



Modified:
   trunk/busybox/include/usage.h
   trunk/busybox/procps/kill.c


Changeset:
Modified: trunk/busybox/include/usage.h
===================================================================
--- trunk/busybox/include/usage.h	2009-02-07 06:57:37 UTC (rev 25260)
+++ trunk/busybox/include/usage.h	2009-02-07 22:30:39 UTC (rev 25261)
@@ -2123,11 +2123,12 @@
        "$ killall apache\n"
 
 #define killall5_trivial_usage \
-       "[-l] [-SIG]"
+       "[-l] [-SIG] [-o PID]..."
 #define killall5_full_usage "\n\n" \
        "Send a signal (default is TERM) to all processes outside current session\n" \
      "\nOptions:" \
      "\n	-l	List all signal names and numbers" \
+     "\n	-o PID	Do not signal this PID" \
 /*   "\n	-s SIG	Yet another way of specifying SIG" */ \
 
 #define klogd_trivial_usage \

Modified: trunk/busybox/procps/kill.c
===================================================================
--- trunk/busybox/procps/kill.c	2009-02-07 06:57:37 UTC (rev 25260)
+++ trunk/busybox/procps/kill.c	2009-02-07 22:30:39 UTC (rev 25261)
@@ -92,11 +92,18 @@
 		quiet = 1;
 		arg = *++argv;
 		argc--;
-		if (argc < 1) bb_show_usage();
-		if (arg[0] != '-') goto do_it_now;
+		if (argc < 1)
+			bb_show_usage();
+		if (arg[0] != '-')
+			goto do_it_now;
 	}
 
 	arg++; /* skip '-' */
+
+	/* -o PID? (if present, it always is at the end of command line) */
+	if (killall5 && arg[0] == 'o')
+		goto do_it_now;
+
 	if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
 		argc--;
 		arg = *++argv;
@@ -109,25 +116,57 @@
 	arg = *++argv;
 	argc--;
 
-do_it_now:
+ do_it_now:
 	pid = getpid();
 
 	if (killall5) {
 		pid_t sid;
 		procps_status_t* p = NULL;
+		int ret = 0;
 
-		/* Find out our own session id */
+		/* Find out our session id */
 		sid = getsid(pid);
-		/* Now stop all processes */
+		/* Stop all processes */
 		kill(-1, SIGSTOP);
-		/* Now kill all processes except our session */
+		/* Signal all processes except those in our session */
 		while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) {
-			if (p->sid != (unsigned)sid && p->pid != (unsigned)pid && p->pid != 1)
-				kill(p->pid, signo);
+			int i;
+
+			if (p->sid == (unsigned)sid
+			 || p->pid == (unsigned)pid
+			 || p->pid == 1)
+				continue;
+
+			/* All remaining args must be -o PID options.
+			 * Check p->pid against them. */
+			for (i = 0; i < argc; i++) {
+				pid_t omit;
+
+				arg = argv[i];
+				if (arg[0] != '-' || arg[1] != 'o') {
+					bb_error_msg("bad option '%s'", arg);
+					ret = 1;
+					goto resume;
+				}
+				arg += 2;
+				if (!arg[0] && argv[++i])
+					arg = argv[i];
+				omit = bb_strtoi(arg, NULL, 10);
+				if (errno) {
+					bb_error_msg("bad pid '%s'", arg);
+					ret = 1;
+					goto resume;
+				}
+				if (p->pid == omit)
+					goto dont_kill;
+			}
+			kill(p->pid, signo);
+ dont_kill: ;
 		}
+ resume:
 		/* And let them continue */
 		kill(-1, SIGCONT);
-		return 0;
+		return ret;
 	}
 
 	/* Pid or name is required for kill/killall */



More information about the busybox-cvs mailing list