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 | |
parent | a6c467f6d134f1fb906806f4cf3b6ca401b6a616 (diff) | |
download | busybox-dd4cb2b31eabe5c69144dfb20fd08ebc625175b1.tar.gz |
hush: stop generating extra empty pipes in parse stage.
Diffstat (limited to 'shell')
-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) && child->argv == NULL && child->redirects == NULL ) { - debug_printf_parse("done_command: skipping null command\n"); - return 0; + debug_printf_parse("done_command: skipping null cmd, num_progs=%d\n", pi->num_progs); + return pi->num_progs; } pi->num_progs++; debug_printf_parse("done_command: ++num_progs=%d\n", pi->num_progs); @@ -2712,26 +2712,28 @@ static int done_command(struct p_context *ctx) ctx->child = child; /* but ctx->pipe and ctx->list_head remain unchanged */ - return 0; + return pi->num_progs; /* used only for 0/nonzero check */ } static int done_pipe(struct p_context *ctx, pipe_style type) { struct pipe *new_p; + int not_null; debug_printf_parse("done_pipe entered, followup %d\n", type); - done_command(ctx); /* implicit closure of previous command */ + not_null = done_command(ctx); /* implicit closure of previous command */ ctx->pipe->followup = type; ctx->pipe->r_mode = ctx->res_w; - new_p = new_pipe(); - ctx->pipe->next = new_p; - ctx->pipe = new_p; - ctx->child = NULL; -// TODO: even just <enter> on command line basically generates -// tree of three NOPs (!). -// Can we detect that previous done_command have seen "skipping null command" -// condition and NOT create new pipe here? - done_command(ctx); /* set up new pipe to accept commands */ + /* Without this check, even just <enter> on command line generates + * tree of three NOPs (!). Which is harmless but annoying. + * IOW: it is safe to do it unconditionally. */ + if (not_null) { + new_p = new_pipe(); + ctx->pipe->next = new_p; + ctx->pipe = new_p; + ctx->child = NULL; + done_command(ctx); /* set up new pipe to accept commands */ + } debug_printf_parse("done_pipe return 0\n"); return 0; } |