From 45b71cd16ecff44cc2181ca1d2815dcb1695e249 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Tue, 28 Dec 2010 13:28:24 +0000 Subject: [PATCH] sh: Make expansion errors in optimized command substitution non-fatal. 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). --- bin/sh/eval.c | 16 +++++++++++++++- tools/regression/bin/sh/expansion/cmdsubst5.0 | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tools/regression/bin/sh/expansion/cmdsubst5.0 diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 5bae2f2b2046..596a86cbbdf5 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -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; @@ -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) diff --git a/tools/regression/bin/sh/expansion/cmdsubst5.0 b/tools/regression/bin/sh/expansion/cmdsubst5.0 new file mode 100644 index 000000000000..afca3719e8b0 --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst5.0 @@ -0,0 +1,5 @@ +# $FreeBSD$ + +unset v +exec 2>/dev/null +! y=$(: ${v?})