diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-08 17:28:45 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-08 17:28:45 +0100 |
commit | 1eada9ad8d31addd57213a072ddfc278e5776740 (patch) | |
tree | fdea7ec9f21b4b23b132a867fb797d1848c29089 | |
parent | 830ea35484cecb8b4cdbe0f30cc5d573ff0e3411 (diff) | |
download | busybox-w32-1eada9ad8d31addd57213a072ddfc278e5776740.tar.gz busybox-w32-1eada9ad8d31addd57213a072ddfc278e5776740.tar.bz2 busybox-w32-1eada9ad8d31addd57213a072ddfc278e5776740.zip |
hush: simplify insert_bg_jobs
function old new delta
insert_bg_job 366 281 -85
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c index 5e51adfdc..78a8f5c03 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -6983,12 +6983,12 @@ static const char *get_cmdtext(struct pipe *pi) | |||
6983 | * On subsequent bg argv is trashed, but we won't use it */ | 6983 | * On subsequent bg argv is trashed, but we won't use it */ |
6984 | if (pi->cmdtext) | 6984 | if (pi->cmdtext) |
6985 | return pi->cmdtext; | 6985 | return pi->cmdtext; |
6986 | |||
6986 | argv = pi->cmds[0].argv; | 6987 | argv = pi->cmds[0].argv; |
6987 | if (!argv || !argv[0]) { | 6988 | if (!argv) { |
6988 | pi->cmdtext = xzalloc(1); | 6989 | pi->cmdtext = xzalloc(1); |
6989 | return pi->cmdtext; | 6990 | return pi->cmdtext; |
6990 | } | 6991 | } |
6991 | |||
6992 | len = 0; | 6992 | len = 0; |
6993 | do { | 6993 | do { |
6994 | len += strlen(*argv) + 1; | 6994 | len += strlen(*argv) + 1; |
@@ -6997,9 +6997,7 @@ static const char *get_cmdtext(struct pipe *pi) | |||
6997 | pi->cmdtext = p; | 6997 | pi->cmdtext = p; |
6998 | argv = pi->cmds[0].argv; | 6998 | argv = pi->cmds[0].argv; |
6999 | do { | 6999 | do { |
7000 | len = strlen(*argv); | 7000 | p = stpcpy(p, *argv); |
7001 | memcpy(p, *argv, len); | ||
7002 | p += len; | ||
7003 | *p++ = ' '; | 7001 | *p++ = ' '; |
7004 | } while (*++argv); | 7002 | } while (*++argv); |
7005 | p[-1] = '\0'; | 7003 | p[-1] = '\0'; |
@@ -7965,8 +7963,8 @@ static int run_list(struct pipe *pi) | |||
7965 | /* We ran a builtin, function, or group. | 7963 | /* We ran a builtin, function, or group. |
7966 | * rcode is already known | 7964 | * rcode is already known |
7967 | * and we don't need to wait for anything. */ | 7965 | * and we don't need to wait for anything. */ |
7968 | G.last_exitcode = rcode; | ||
7969 | debug_printf_exec(": builtin/func exitcode %d\n", rcode); | 7966 | debug_printf_exec(": builtin/func exitcode %d\n", rcode); |
7967 | G.last_exitcode = rcode; | ||
7970 | check_and_run_traps(); | 7968 | check_and_run_traps(); |
7971 | #if ENABLE_HUSH_LOOPS | 7969 | #if ENABLE_HUSH_LOOPS |
7972 | /* Was it "break" or "continue"? */ | 7970 | /* Was it "break" or "continue"? */ |
@@ -7998,30 +7996,30 @@ static int run_list(struct pipe *pi) | |||
7998 | /* even bash 3.2 doesn't do that well with nested bg: | 7996 | /* even bash 3.2 doesn't do that well with nested bg: |
7999 | * try "{ { sleep 10; echo DEEP; } & echo HERE; } &". | 7997 | * try "{ { sleep 10; echo DEEP; } & echo HERE; } &". |
8000 | * I'm NOT treating inner &'s as jobs */ | 7998 | * I'm NOT treating inner &'s as jobs */ |
8001 | check_and_run_traps(); | ||
8002 | #if ENABLE_HUSH_JOB | 7999 | #if ENABLE_HUSH_JOB |
8003 | if (G.run_list_level == 1) | 8000 | if (G.run_list_level == 1) |
8004 | insert_bg_job(pi); | 8001 | insert_bg_job(pi); |
8005 | #endif | 8002 | #endif |
8006 | /* Last command's pid goes to $! */ | 8003 | /* Last command's pid goes to $! */ |
8007 | G.last_bg_pid = pi->cmds[pi->num_cmds - 1].pid; | 8004 | G.last_bg_pid = pi->cmds[pi->num_cmds - 1].pid; |
8008 | G.last_exitcode = rcode = EXIT_SUCCESS; | ||
8009 | debug_printf_exec(": cmd&: exitcode EXIT_SUCCESS\n"); | 8005 | debug_printf_exec(": cmd&: exitcode EXIT_SUCCESS\n"); |
8006 | /* Check pi->pi_inverted? "! sleep 1 & echo $?": bash says 1. dash and ash says 0 */ | ||
8007 | G.last_exitcode = rcode = EXIT_SUCCESS; | ||
8008 | check_and_run_traps(); | ||
8010 | } else { | 8009 | } else { |
8011 | #if ENABLE_HUSH_JOB | 8010 | #if ENABLE_HUSH_JOB |
8012 | if (G.run_list_level == 1 && G_interactive_fd) { | 8011 | if (G.run_list_level == 1 && G_interactive_fd) { |
8013 | /* Waits for completion, then fg's main shell */ | 8012 | /* Waits for completion, then fg's main shell */ |
8014 | rcode = checkjobs_and_fg_shell(pi); | 8013 | rcode = checkjobs_and_fg_shell(pi); |
8015 | debug_printf_exec(": checkjobs_and_fg_shell exitcode %d\n", rcode); | 8014 | debug_printf_exec(": checkjobs_and_fg_shell exitcode %d\n", rcode); |
8016 | check_and_run_traps(); | ||
8017 | } else | 8015 | } else |
8018 | #endif | 8016 | #endif |
8019 | { /* This one just waits for completion */ | 8017 | { /* This one just waits for completion */ |
8020 | rcode = checkjobs(pi, 0 /*(no pid to wait for)*/); | 8018 | rcode = checkjobs(pi, 0 /*(no pid to wait for)*/); |
8021 | debug_printf_exec(": checkjobs exitcode %d\n", rcode); | 8019 | debug_printf_exec(": checkjobs exitcode %d\n", rcode); |
8022 | check_and_run_traps(); | ||
8023 | } | 8020 | } |
8024 | G.last_exitcode = rcode; | 8021 | G.last_exitcode = rcode; |
8022 | check_and_run_traps(); | ||
8025 | } | 8023 | } |
8026 | } | 8024 | } |
8027 | 8025 | ||