diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-25 14:34:30 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-25 14:34:30 +0000 |
| commit | ba7cf260fdd246b4e91d26e92cd582e026543d4a (patch) | |
| tree | 4bf9ed482abd9d954712bb82a08ffa4e31502c2e /shell | |
| parent | 0a83fc398495799b4c96f3cd07304d38181cfc6f (diff) | |
| download | busybox-w32-ba7cf260fdd246b4e91d26e92cd582e026543d4a.tar.gz busybox-w32-ba7cf260fdd246b4e91d26e92cd582e026543d4a.tar.bz2 busybox-w32-ba7cf260fdd246b4e91d26e92cd582e026543d4a.zip | |
hush: fix 'echo abc`sleep 5`def' + Ctrl-Z and Ctrl-C bugs. +50 bytes of code.
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/shell/hush.c b/shell/hush.c index a7b55415f..800b0f970 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -2158,7 +2158,10 @@ static int run_list_real(struct pipe *pi) | |||
| 2158 | exit(rcode); | 2158 | exit(rcode); |
| 2159 | } | 2159 | } |
| 2160 | ret: | 2160 | ret: |
| 2161 | run_list_level--; | 2161 | if (!--run_list_level && interactive_fd) { |
| 2162 | signal(SIGTSTP, SIG_IGN); | ||
| 2163 | signal(SIGINT, SIG_IGN); | ||
| 2164 | } | ||
| 2162 | #endif | 2165 | #endif |
| 2163 | debug_printf_exec("run_list_real lvl %d return %d\n", run_list_level + 1, rcode); | 2166 | debug_printf_exec("run_list_real lvl %d return %d\n", run_list_level + 1, rcode); |
| 2164 | return rcode; | 2167 | return rcode; |
| @@ -3130,7 +3133,9 @@ static FILE *generate_stream_from_list(struct pipe *head) | |||
| 3130 | { | 3133 | { |
| 3131 | FILE *pf; | 3134 | FILE *pf; |
| 3132 | int pid, channel[2]; | 3135 | int pid, channel[2]; |
| 3133 | if (pipe(channel) < 0) bb_perror_msg_and_die("pipe"); | 3136 | |
| 3137 | if (pipe(channel) < 0) | ||
| 3138 | bb_perror_msg_and_die("pipe"); | ||
| 3134 | #if BB_MMU | 3139 | #if BB_MMU |
| 3135 | pid = fork(); | 3140 | pid = fork(); |
| 3136 | #else | 3141 | #else |
| @@ -3144,12 +3149,19 @@ static FILE *generate_stream_from_list(struct pipe *head) | |||
| 3144 | dup2(channel[1], 1); | 3149 | dup2(channel[1], 1); |
| 3145 | close(channel[1]); | 3150 | close(channel[1]); |
| 3146 | } | 3151 | } |
| 3152 | /* Prevent it from trying to handle ctrl-z etc */ | ||
| 3153 | run_list_level = 1; | ||
| 3154 | /* Process substitution is not considered to be usual | ||
| 3155 | * 'command execution'. | ||
| 3156 | * SUSv3 says ctrl-Z should be ignored, ctrl-C should not. */ | ||
| 3157 | /* Not needed, we are relying on it being disabled | ||
| 3158 | * everywhere outside actual command execution. */ | ||
| 3159 | /*set_jobctrl_sighandler(SIG_IGN);*/ | ||
| 3160 | set_misc_sighandler(SIG_DFL); | ||
| 3147 | _exit(run_list_real(head)); /* leaks memory */ | 3161 | _exit(run_list_real(head)); /* leaks memory */ |
| 3148 | } | 3162 | } |
| 3149 | debug_printf("forked child %d\n", pid); | ||
| 3150 | close(channel[1]); | 3163 | close(channel[1]); |
| 3151 | pf = fdopen(channel[0], "r"); | 3164 | pf = fdopen(channel[0], "r"); |
| 3152 | debug_printf("pipe on FILE *%p\n", pf); | ||
| 3153 | return pf; | 3165 | return pf; |
| 3154 | } | 3166 | } |
| 3155 | 3167 | ||
| @@ -3199,9 +3211,9 @@ static int process_command_subs(o_string *dest, struct p_context *ctx, | |||
| 3199 | * at the same time. That would be a lot of work, and contrary | 3211 | * at the same time. That would be a lot of work, and contrary |
| 3200 | * to the KISS philosophy of this program. */ | 3212 | * to the KISS philosophy of this program. */ |
| 3201 | mark_closed(fileno(p)); | 3213 | mark_closed(fileno(p)); |
| 3202 | retcode = pclose(p); | 3214 | retcode = fclose(p); |
| 3203 | free_pipe_list(inner.list_head, 0); | 3215 | free_pipe_list(inner.list_head, 0); |
| 3204 | debug_printf("pclosed, retcode=%d\n", retcode); | 3216 | debug_printf("closed FILE from child, retcode=%d\n", retcode); |
| 3205 | return retcode; | 3217 | return retcode; |
| 3206 | } | 3218 | } |
| 3207 | #endif | 3219 | #endif |
