From df6b9adb7f429266f4faf79629df957f76d736f3 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 21 Aug 2011 14:55:15 -0700 Subject: [PATCH] sh: Remove special support for background simple commands. It expands the arguments in the parent shell process, which is incorrect. Obtained-from: FreeBSD 223282 --- bin/sh/eval.c | 10 ++++------ bin/sh/nodetypes | 3 +-- bin/sh/parser.c | 7 +++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 32ee05ec8f..566bd58cca 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)eval.c 8.9 (Berkeley) 6/8/95 - * $FreeBSD: src/bin/sh/eval.c,v 1.111 2011/06/17 13:03:49 jilles Exp $ + * $FreeBSD: src/bin/sh/eval.c,v 1.112 2011/06/18 23:58:59 jilles Exp $ */ #include @@ -897,14 +897,13 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd) } /* Fork off a child process if necessary. */ - if (cmd->ncmd.backgnd - || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN) + if (((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN) && ((flags & EV_EXIT) == 0 || have_traps())) || ((flags & EV_BACKCMD) != 0 && (cmdentry.cmdtype != CMDBUILTIN || !safe_builtin(cmdentry.u.index, argc, argv)))) { jp = makejob(cmd, 1); - mode = cmd->ncmd.backgnd; + mode = FORK_FG; if (flags & EV_BACKCMD) { mode = FORK_NOJOB; if (pipe(pip) < 0) @@ -1071,8 +1070,7 @@ parent: /* parent process gets here (if we forked) */ backcmd->fd = pip[0]; close(pip[1]); backcmd->jp = jp; - } else - exitstatus = 0; + } out: if (lastarg) diff --git a/bin/sh/nodetypes b/bin/sh/nodetypes index e311f23c20..f2475a1dba 100644 --- a/bin/sh/nodetypes +++ b/bin/sh/nodetypes @@ -34,7 +34,7 @@ # SUCH DAMAGE. # # @(#)nodetypes 8.2 (Berkeley) 5/4/95 -# $FreeBSD: src/bin/sh/nodetypes,v 1.11 2011/06/17 13:03:49 jilles Exp $ +# $FreeBSD: src/bin/sh/nodetypes,v 1.12 2011/06/18 23:58:59 jilles Exp $ # This file describes the nodes used in parse trees. Unindented lines # contain a node type followed by a structure tag. Subsequent indented @@ -60,7 +60,6 @@ NSEMI nbinary # two commands separated by a semicolon NCMD ncmd # a simple command type int - backgnd int # set to run command in background args nodeptr # the arguments redirect nodeptr # list of file redirections diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 1aaaac9148..aac54b8c8c 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)parser.c 8.7 (Berkeley) 5/16/95 - * $FreeBSD: src/bin/sh/parser.c,v 1.114 2011/06/17 13:03:49 jilles Exp $ + * $FreeBSD: src/bin/sh/parser.c,v 1.115 2011/06/18 23:58:59 jilles Exp $ */ #include @@ -239,8 +239,8 @@ list(int nlflag, int erflag) n2 = andor(); tok = readtoken(); if (tok == TBACKGND) { - if (n2->type == NCMD || n2->type == NPIPE) { - n2->ncmd.backgnd = 1; + if (n2->type == NPIPE) { + n2->npipe.backgnd = 1; } else if (n2->type == NREDIR) { n2->type = NBACKGND; } else { @@ -688,7 +688,6 @@ simplecmd(union node **rpp, union node *redir) *rpp = NULL; n = (union node *)stalloc(sizeof (struct ncmd)); n->type = NCMD; - n->ncmd.backgnd = 0; n->ncmd.args = args; n->ncmd.redirect = redir; return n; -- 2.41.0