summaryrefslogtreecommitdiffstats
path: root/bin/sh/eval.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-04-25 20:54:12 +0000
committerjilles <jilles@FreeBSD.org>2011-04-25 20:54:12 +0000
commit7b50330e011dfd112eaa530e79b7b29d8152e6d6 (patch)
tree0826bffcc674a347b694041997a07842486d94c1 /bin/sh/eval.c
parente9f95ffefb85c41251ae3400a0cd59d46d241f60 (diff)
downloadFreeBSD-src-7b50330e011dfd112eaa530e79b7b29d8152e6d6.zip
FreeBSD-src-7b50330e011dfd112eaa530e79b7b29d8152e6d6.tar.gz
sh: Set $? to 0 for background commands.
For backgrounded pipelines and subshells, the previous value of $? was being preserved, which is incorrect. For backgrounded simple commands containing a command substitution, the status of the last command substitution was returned instead of 0. If fork() fails, this is an error.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r--bin/sh/eval.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 6f89041..b0ee28e 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -420,7 +420,8 @@ evalsubshell(union node *n, int flags)
INTOFF;
exitstatus = waitforjob(jp, (int *)NULL);
INTON;
- }
+ } else
+ exitstatus = 0;
}
@@ -559,7 +560,8 @@ evalpipe(union node *n)
exitstatus = waitforjob(jp, (int *)NULL);
TRACE(("evalpipe: job done exit status %d\n", exitstatus));
INTON;
- }
+ } else
+ exitstatus = 0;
}
@@ -1056,7 +1058,8 @@ parent: /* parent process gets here (if we forked) */
backcmd->fd = pip[0];
close(pip[1]);
backcmd->jp = jp;
- }
+ } else
+ exitstatus = 0;
out:
if (lastarg)
OpenPOWER on IntegriCloud