diff options
author | jilles <jilles@FreeBSD.org> | 2013-02-03 15:54:57 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-02-03 15:54:57 +0000 |
commit | 6fa139d56eac8251b9a64c249c8e6fc8131f405c (patch) | |
tree | 798963ecfeaa133433ad99b27533d07fa1521c76 /bin/sh/eval.c | |
parent | aa08976cf0559eb6c97a1886ea652e0f839759e5 (diff) | |
download | FreeBSD-src-6fa139d56eac8251b9a64c249c8e6fc8131f405c.zip FreeBSD-src-6fa139d56eac8251b9a64c249c8e6fc8131f405c.tar.gz |
sh: Expand here documents in the current process.
Expand here documents at the same point other redirections are expanded but
use a non-fork subshell environment (like simple command substitutions) for
compatibility. Substitition errors result in an empty here document like
before.
As a result, a fork is avoided for short (<4K) expanded here documents.
Unexpanded here documents (with quoted end marker after <<) are not affected
by this change. They already only forked when >4K.
Side effects:
* Order of expansion is slightly different.
* Slow expansions are not executed in parallel with the redirected command.
* A non-fork subshell environment is subtly different from a forked process.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r-- | bin/sh/eval.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 7817806..66ae40e 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -92,6 +92,7 @@ static void evalfor(union node *, int); static union node *evalcase(union node *); static void evalsubshell(union node *, int); static void evalredir(union node *, int); +static void exphere(union node *, struct arglist *); static void expredir(union node *); static void evalpipe(union node *); static int is_valid_fast_cmdsubst(union node *n); @@ -488,6 +489,37 @@ evalredir(union node *n, int flags) } +static void +exphere(union node *redir, struct arglist *fn) +{ + struct jmploc jmploc; + struct jmploc *savehandler; + struct localvar *savelocalvars; + int need_longjmp = 0; + + redir->nhere.expdoc = nullstr; + savelocalvars = localvars; + localvars = NULL; + forcelocal++; + savehandler = handler; + if (setjmp(jmploc.loc)) + need_longjmp = exception != EXERROR && exception != EXEXEC; + else { + handler = &jmploc; + expandarg(redir->nhere.doc, fn, 0); + redir->nhere.expdoc = fn->list->text; + INTOFF; + } + handler = savehandler; + forcelocal--; + poplocalvars(); + localvars = savelocalvars; + if (need_longjmp) + longjmp(handler->loc, 1); + INTON; +} + + /* * Compute the names of the files in a redirection list. */ @@ -516,6 +548,9 @@ expredir(union node *n) fixredir(redir, fn.list->text, 1); } break; + case NXHERE: + exphere(redir, &fn); + break; } } } |