diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-05 15:11:40 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-05 15:11:40 +0000 |
commit | dd4cb2b31eabe5c69144dfb20fd08ebc625175b1 (patch) | |
tree | d074a1749ee5b1da6dea1ca4218d3c72c9f734fd /shell/hush.c | |
parent | a6c467f6d134f1fb906806f4cf3b6ca401b6a616 (diff) | |
download | busybox-w32-dd4cb2b31eabe5c69144dfb20fd08ebc625175b1.tar.gz busybox-w32-dd4cb2b31eabe5c69144dfb20fd08ebc625175b1.tar.bz2 busybox-w32-dd4cb2b31eabe5c69144dfb20fd08ebc625175b1.zip |
hush: stop generating extra empty pipes in parse stage.
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/shell/hush.c b/shell/hush.c index eb6f37f15..a299b0123 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2685,8 +2685,8 @@ static int done_command(struct p_context *ctx) | |||
2685 | && child->argv == NULL | 2685 | && child->argv == NULL |
2686 | && child->redirects == NULL | 2686 | && child->redirects == NULL |
2687 | ) { | 2687 | ) { |
2688 | debug_printf_parse("done_command: skipping null command\n"); | 2688 | debug_printf_parse("done_command: skipping null cmd, num_progs=%d\n", pi->num_progs); |
2689 | return 0; | 2689 | return pi->num_progs; |
2690 | } | 2690 | } |
2691 | pi->num_progs++; | 2691 | pi->num_progs++; |
2692 | debug_printf_parse("done_command: ++num_progs=%d\n", pi->num_progs); | 2692 | debug_printf_parse("done_command: ++num_progs=%d\n", pi->num_progs); |
@@ -2712,26 +2712,28 @@ static int done_command(struct p_context *ctx) | |||
2712 | ctx->child = child; | 2712 | ctx->child = child; |
2713 | /* but ctx->pipe and ctx->list_head remain unchanged */ | 2713 | /* but ctx->pipe and ctx->list_head remain unchanged */ |
2714 | 2714 | ||
2715 | return 0; | 2715 | return pi->num_progs; /* used only for 0/nonzero check */ |
2716 | } | 2716 | } |
2717 | 2717 | ||
2718 | static int done_pipe(struct p_context *ctx, pipe_style type) | 2718 | static int done_pipe(struct p_context *ctx, pipe_style type) |
2719 | { | 2719 | { |
2720 | struct pipe *new_p; | 2720 | struct pipe *new_p; |
2721 | int not_null; | ||
2721 | 2722 | ||
2722 | debug_printf_parse("done_pipe entered, followup %d\n", type); | 2723 | debug_printf_parse("done_pipe entered, followup %d\n", type); |
2723 | done_command(ctx); /* implicit closure of previous command */ | 2724 | not_null = done_command(ctx); /* implicit closure of previous command */ |
2724 | ctx->pipe->followup = type; | 2725 | ctx->pipe->followup = type; |
2725 | ctx->pipe->r_mode = ctx->res_w; | 2726 | ctx->pipe->r_mode = ctx->res_w; |
2726 | new_p = new_pipe(); | 2727 | /* Without this check, even just <enter> on command line generates |
2727 | ctx->pipe->next = new_p; | 2728 | * tree of three NOPs (!). Which is harmless but annoying. |
2728 | ctx->pipe = new_p; | 2729 | * IOW: it is safe to do it unconditionally. */ |
2729 | ctx->child = NULL; | 2730 | if (not_null) { |
2730 | // TODO: even just <enter> on command line basically generates | 2731 | new_p = new_pipe(); |
2731 | // tree of three NOPs (!). | 2732 | ctx->pipe->next = new_p; |
2732 | // Can we detect that previous done_command have seen "skipping null command" | 2733 | ctx->pipe = new_p; |
2733 | // condition and NOT create new pipe here? | 2734 | ctx->child = NULL; |
2734 | done_command(ctx); /* set up new pipe to accept commands */ | 2735 | done_command(ctx); /* set up new pipe to accept commands */ |
2736 | } | ||
2735 | debug_printf_parse("done_pipe return 0\n"); | 2737 | debug_printf_parse("done_pipe return 0\n"); |
2736 | return 0; | 2738 | return 0; |
2737 | } | 2739 | } |