From: Peter Avalos Date: Sun, 21 Aug 2011 21:36:38 +0000 (-0700) Subject: sh: Reduce unnecessary forks with eval. X-Git-Tag: v2.12.0~147 X-Git-Url: https://gitweb.dragonflybsd.org/~nant/dragonfly.git/commitdiff_plain/f15f366852663832eb02933efecc062dbff4bc59 sh: Reduce unnecessary forks with eval. The eval special builtin now runs the code with EV_EXIT if it was run with EV_EXIT itself. In particular, this eliminates one fork when a command substitution contains an eval command that ends with an external program or a subshell. Obtained-from: FreeBSD 223163 --- diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 6f0615e096..ecc53f4c46 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)eval.c 8.9 (Berkeley) 6/8/95 - * $FreeBSD: src/bin/sh/eval.c,v 1.109 2011/06/12 23:06:04 jilles Exp $ + * $FreeBSD: src/bin/sh/eval.c,v 1.110 2011/06/16 21:50:28 jilles Exp $ */ #include @@ -141,7 +141,7 @@ evalcmd(int argc, char **argv) STPUTC('\0', concat); p = grabstackstr(concat); } - evalstring(p, builtin_flags & EV_TESTED); + evalstring(p, builtin_flags); } else exitstatus = 0; return exitstatus; @@ -911,6 +911,7 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd) dup2(pip[1], 1); close(pip[1]); } + flags &= ~EV_BACKCMD; } flags |= EV_EXIT; } diff --git a/tools/regression/bin/sh/expansion/cmdsubst11.0 b/tools/regression/bin/sh/expansion/cmdsubst11.0 new file mode 100644 index 0000000000..14a3597ff8 --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst11.0 @@ -0,0 +1,5 @@ +# $FreeBSD: src/tools/regression/bin/sh/expansion/cmdsubst11.0,v 1.1 2011/06/16 21:50:28 jilles Exp $ + +# Not required by POSIX but useful for efficiency. + +[ $$ = $(eval '${SH} -c echo\ \$PPID') ]