[git commit] hush: fix kill builtin without jobs support

Denys Vlasenko vda.linux at googlemail.com
Mon Jan 9 04:47:57 UTC 2017


commit: https://git.busybox.net/busybox/commit/?id=fd68f1e80dbed81e42a0298db5fcf578e8d944a9
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/hush.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/shell/hush.c b/shell/hush.c
index 01c334a..247ad7a 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9443,7 +9443,7 @@ static struct pipe *parse_jobspec(const char *str)
 			return pi;
 		}
 	}
-	bb_error_msg("%d: no such job", jobnum);
+	bb_error_msg("%u: no such job", jobnum);
 	return NULL;
 }
 
@@ -9691,9 +9691,9 @@ static int FAST_FUNC builtin_kill(char **argv)
 {
 	int ret = 0;
 
-	argv = skip_dash_dash(argv);
-	if (argv[0] && strcmp(argv[0], "-l") != 0) {
-		int i = 0;
+# if ENABLE_HUSH_JOB
+	if (argv[1] && strcmp(argv[1], "-l") != 0) {
+		int i = 1;
 
 		do {
 			struct pipe *pi;
@@ -9735,12 +9735,9 @@ static int FAST_FUNC builtin_kill(char **argv)
 				n = 1;
 			dst = alloca(n * sizeof(int)*4);
 			argv[i] = dst;
-#if ENABLE_HUSH_JOB
 			if (G_interactive_fd)
 				dst += sprintf(dst, " -%u", (int)pi->pgrp);
-			else
-#endif
-			for (j = 0; j < n; j++) {
+			else for (j = 0; j < n; j++) {
 				struct command *cmd = &pi->cmds[j];
 				/* Skip exited members of the job */
 				if (cmd->pid == 0)
@@ -9755,13 +9752,12 @@ static int FAST_FUNC builtin_kill(char **argv)
 			*dst = '\0';
 		} while (argv[++i]);
 	}
+# endif
 
-	if (argv[0] || ret == 0) {
-		argv--;
-		argv[0] = (char*)"kill"; /* why? think about "kill -- PID" */
-		/* kill_main also handles "killall" etc, so it does look at argv[0]! */
+	if (argv[1] || ret == 0) {
 		ret = run_applet_main(argv, kill_main);
 	}
+	/* else: ret = 1, "kill %bad_jobspec" case */
 	return ret;
 }
 #endif


More information about the busybox-cvs mailing list