sh: Do not call exitshell() from evalcommand() unless evalcommand() forked
itself. This ensures that certain traps caused by builtins are executed.
This commit is contained in:
parent
0fa61e2f67
commit
e23a66ac83
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=217035
@ -671,6 +671,7 @@ safe_builtin(int idx, int argc, char **argv)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Execute a simple command.
|
* Execute a simple command.
|
||||||
|
* Note: This may or may not return if (flags & EV_EXIT).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -707,6 +708,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
|||||||
arglist.lastp = &arglist.list;
|
arglist.lastp = &arglist.list;
|
||||||
varlist.lastp = &varlist.list;
|
varlist.lastp = &varlist.list;
|
||||||
varflag = 1;
|
varflag = 1;
|
||||||
|
jp = NULL;
|
||||||
do_clearcmdentry = 0;
|
do_clearcmdentry = 0;
|
||||||
oexitstatus = exitstatus;
|
oexitstatus = exitstatus;
|
||||||
exitstatus = 0;
|
exitstatus = 0;
|
||||||
@ -965,7 +967,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
|||||||
evalskip = 0;
|
evalskip = 0;
|
||||||
skipcount = 0;
|
skipcount = 0;
|
||||||
}
|
}
|
||||||
if (flags & EV_EXIT)
|
if (jp)
|
||||||
exitshell(exitstatus);
|
exitshell(exitstatus);
|
||||||
} else if (cmdentry.cmdtype == CMDBUILTIN) {
|
} else if (cmdentry.cmdtype == CMDBUILTIN) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -1013,13 +1015,12 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
|||||||
out1 = &output;
|
out1 = &output;
|
||||||
out2 = &errout;
|
out2 = &errout;
|
||||||
freestdout();
|
freestdout();
|
||||||
|
handler = savehandler;
|
||||||
if (e != EXSHELLPROC) {
|
if (e != EXSHELLPROC) {
|
||||||
commandname = savecmdname;
|
commandname = savecmdname;
|
||||||
if (flags & EV_EXIT) {
|
if (jp)
|
||||||
exitshell(exitstatus);
|
exitshell(exitstatus);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
handler = savehandler;
|
|
||||||
if (flags == EV_BACKCMD) {
|
if (flags == EV_BACKCMD) {
|
||||||
backcmd->buf = memout.buf;
|
backcmd->buf = memout.buf;
|
||||||
backcmd->nleft = memout.nextc - memout.buf;
|
backcmd->nleft = memout.nextc - memout.buf;
|
||||||
|
17
tools/regression/bin/sh/builtins/trap4.0
Normal file
17
tools/regression/bin/sh/builtins/trap4.0
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
|
||||||
|
trap 'rm -rf $T' 0
|
||||||
|
cd $T || exit 3
|
||||||
|
mkfifo fifo1
|
||||||
|
|
||||||
|
v=$(
|
||||||
|
exec 3>&1
|
||||||
|
: <fifo1 &
|
||||||
|
{
|
||||||
|
wait $!
|
||||||
|
trap 'trap "" PIPE; echo trapped >&3 2>/dev/null' PIPE
|
||||||
|
echo x 2>/dev/null
|
||||||
|
} >fifo1
|
||||||
|
)
|
||||||
|
test "$v" = trapped
|
Loading…
Reference in New Issue
Block a user