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.
This commit is contained in:
Jilles Tjoelker 2011-04-25 20:54:12 +00:00
parent 1792d820be
commit 03b3a844d0
4 changed files with 19 additions and 3 deletions

View File

@ -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 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
backcmd->fd = pip[0];
close(pip[1]);
backcmd->jp = jp;
}
} else
exitstatus = 0;
out:
if (lastarg)

View File

@ -0,0 +1,3 @@
# $FreeBSD$
: `false` &

View File

@ -0,0 +1,5 @@
# $FreeBSD$
f() { return 42; }
f
: | : &

View File

@ -0,0 +1,5 @@
# $FreeBSD$
f() { return 42; }
f
(:) &