Skip to content

Commit

Permalink
sh: Make expansion errors in optimized command substitution non-fatal.
Browse files Browse the repository at this point in the history
Command substitutions consisting of a single simple command are executed in
the main shell process but this should be invisible apart from performance
and very few exceptions such as $(trap).
  • Loading branch information
jillest committed Dec 28, 2010
1 parent e29f3cc commit 45b71cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bin/sh/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ evalbackcmd(union node *n, struct backcmd *result)
int pip[2];
struct job *jp;
struct stackmark smark; /* unnecessary */
struct jmploc jmploc;
struct jmploc *savehandler;

setstackmark(&smark);
result->fd = -1;
Expand All @@ -590,7 +592,19 @@ evalbackcmd(union node *n, struct backcmd *result)
}
if (n->type == NCMD) {
exitstatus = oexitstatus;
evalcommand(n, EV_BACKCMD, result);
savehandler = handler;
if (setjmp(jmploc.loc)) {
if (exception == EXERROR || exception == EXEXEC)
exitstatus = 2;
else if (exception != 0) {
handler = savehandler;
longjmp(handler->loc, 1);
}
} else {
handler = &jmploc;
evalcommand(n, EV_BACKCMD, result);
}
handler = savehandler;
} else {
exitstatus = 0;
if (pipe(pip) < 0)
Expand Down
5 changes: 5 additions & 0 deletions tools/regression/bin/sh/expansion/cmdsubst5.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# $FreeBSD$

unset v
exec 2>/dev/null
! y=$(: ${v?})

0 comments on commit 45b71cd

Please sign in to comment.