summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-21 10:01:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-21 10:01:14 +0000
commit2f1bb36a557f4ce8e1f5abd177c34dadbc0fb534 (patch)
tree78c0e51c28c953f3493ae4cdb59928f14904dac6 /shell/hush.c
parent87cb2db7039d4f26a9290f4149e9774c4afe4a37 (diff)
downloadbusybox-w32-2f1bb36a557f4ce8e1f5abd177c34dadbc0fb534.tar.gz
busybox-w32-2f1bb36a557f4ce8e1f5abd177c34dadbc0fb534.tar.bz2
busybox-w32-2f1bb36a557f4ce8e1f5abd177c34dadbc0fb534.zip
hush: explain why "pipe; exit $?" doesn't show correct exitcode
Diffstat (limited to '')
-rw-r--r--shell/hush.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/shell/hush.c b/shell/hush.c
index c4b393bce..db93f8dcb 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1541,7 +1541,7 @@ static int run_pipe_real(struct pipe *pi)
1541 1541
1542 pi->running_progs++; 1542 pi->running_progs++;
1543 1543
1544 /* Second and next children need to know ipd of first one */ 1544 /* Second and next children need to know pid of first one */
1545 if (pi->pgrp < 0) 1545 if (pi->pgrp < 0)
1546 pi->pgrp = child->pid; 1546 pi->pgrp = child->pid;
1547 1547
@@ -1612,7 +1612,7 @@ static int run_list_real(struct pipe *pi)
1612 skip_more_in_this_rmode = RES_XXXX; 1612 skip_more_in_this_rmode = RES_XXXX;
1613 if (rmode == RES_THEN || rmode == RES_ELSE) 1613 if (rmode == RES_THEN || rmode == RES_ELSE)
1614 if_code = next_if_code; 1614 if_code = next_if_code;
1615 if (rmode == RES_THEN && if_code) 1615 if (rmode == RES_THEN && if_code)
1616 continue; 1616 continue;
1617 if (rmode == RES_ELSE && !if_code) 1617 if (rmode == RES_ELSE && !if_code)
1618 continue; 1618 continue;
@@ -2814,7 +2814,8 @@ static int parse_stream_outer(struct in_str *inp, int flag)
2814 ctx.type = flag; 2814 ctx.type = flag;
2815 initialize_context(&ctx); 2815 initialize_context(&ctx);
2816 update_ifs_map(); 2816 update_ifs_map();
2817 if (!(flag & FLAG_PARSE_SEMICOLON) || (flag & FLAG_REPARSING)) mapset(";$&|", 0); 2817 if (!(flag & FLAG_PARSE_SEMICOLON) || (flag & FLAG_REPARSING))
2818 mapset(";$&|", 0);
2818 inp->promptmode = 1; 2819 inp->promptmode = 1;
2819 rcode = parse_stream(&temp, &ctx, inp, '\n'); 2820 rcode = parse_stream(&temp, &ctx, inp, '\n');
2820 if (rcode != 1 && ctx.old_flag != 0) { 2821 if (rcode != 1 && ctx.old_flag != 0) {
@@ -2832,7 +2833,7 @@ static int parse_stream_outer(struct in_str *inp, int flag)
2832 temp.nonnull = 0; 2833 temp.nonnull = 0;
2833 temp.quote = 0; 2834 temp.quote = 0;
2834 inp->p = NULL; 2835 inp->p = NULL;
2835 free_pipe_list(ctx.list_head,0); 2836 free_pipe_list(ctx.list_head, 0);
2836 } 2837 }
2837 b_free(&temp); 2838 b_free(&temp);
2838 } while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */ 2839 } while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */
@@ -2862,6 +2863,8 @@ static void setup_job_control(void)
2862{ 2863{
2863 pid_t shell_pgrp; 2864 pid_t shell_pgrp;
2864 2865
2866 saved_task_pgrp = getpgrp();
2867 debug_printf("saved_task_pgrp=%d\n", saved_task_pgrp);
2865 fcntl(interactive_fd, F_SETFD, FD_CLOEXEC); 2868 fcntl(interactive_fd, F_SETFD, FD_CLOEXEC);
2866 2869
2867 /* Loop until we are in the foreground. */ 2870 /* Loop until we are in the foreground. */
@@ -2952,7 +2955,9 @@ int hush_main(int argc, char **argv)
2952 opt = parse_string_outer(optarg, FLAG_PARSE_SEMICOLON); 2955 opt = parse_string_outer(optarg, FLAG_PARSE_SEMICOLON);
2953 goto final_return; 2956 goto final_return;
2954 case 'i': 2957 case 'i':
2955 /*interactive_fd++;*/ //huh?? 2958 // Well, we cannot just declare interactiveness,
2959 // we have to have some stuff (ctty, etc)
2960 /*interactive_fd++;*/
2956 break; 2961 break;
2957 case 'f': 2962 case 'f':
2958 fake_mode++; 2963 fake_mode++;
@@ -2980,8 +2985,6 @@ int hush_main(int argc, char **argv)
2980 saved_tty_pgrp = tcgetpgrp(STDIN_FILENO); 2985 saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
2981 debug_printf("saved_tty_pgrp=%d\n", saved_tty_pgrp); 2986 debug_printf("saved_tty_pgrp=%d\n", saved_tty_pgrp);
2982 if (saved_tty_pgrp >= 0) { 2987 if (saved_tty_pgrp >= 0) {
2983 saved_task_pgrp = getpgrp();
2984 debug_printf("saved_task_pgrp=%d\n", saved_task_pgrp);
2985 /* try to dup to high fd#, >= 255 */ 2988 /* try to dup to high fd#, >= 255 */
2986 interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255); 2989 interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255);
2987 if (interactive_fd < 0) { 2990 if (interactive_fd < 0) {
@@ -2991,17 +2994,14 @@ int hush_main(int argc, char **argv)
2991 /* give up */ 2994 /* give up */
2992 interactive_fd = 0; 2995 interactive_fd = 0;
2993 } 2996 }
2997 // TODO: track & disallow any attempts of user
2998 // to (inadvertently) close/redirect it
2994 } 2999 }
2995 } 3000 }
2996 3001
2997 debug_printf("\ninteractive_fd=%d\n", interactive_fd); 3002 debug_printf("\ninteractive_fd=%d\n", interactive_fd);
2998 if (interactive_fd) { 3003 if (interactive_fd) {
2999 /* Looks like they want an interactive shell */ 3004 /* Looks like they want an interactive shell */
3000#if !ENABLE_FEATURE_SH_EXTRA_QUIET
3001 printf( "\n\n%s hush - the humble shell v0.01 (testing)\n",
3002 BB_BANNER);
3003 printf( "Enter 'help' for a list of built-in commands.\n\n");
3004#endif
3005 setup_job_control(); 3005 setup_job_control();
3006 /* Make xfuncs do cleanup on exit */ 3006 /* Make xfuncs do cleanup on exit */
3007 die_sleep = -1; /* flag */ 3007 die_sleep = -1; /* flag */
@@ -3009,6 +3009,10 @@ int hush_main(int argc, char **argv)
3009 /* xfunc has failed! die die die */ 3009 /* xfunc has failed! die die die */
3010 hush_exit(xfunc_error_retval); 3010 hush_exit(xfunc_error_retval);
3011 } 3011 }
3012#if !ENABLE_FEATURE_SH_EXTRA_QUIET
3013 printf("\n\n%s hush - the humble shell v0.02\n", BB_BANNER);
3014 printf("Enter 'help' for a list of built-in commands.\n\n");
3015#endif
3012 } 3016 }
3013 3017
3014 if (argv[optind] == NULL) { 3018 if (argv[optind] == NULL) {