From c5aef5377cbfc3324cacb13ee94986a5c81f67d9 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 16 Jun 2011 21:50:28 +0000 Subject: [PATCH] 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. This is similar to what r220978 did for functions. --- bin/sh/eval.c | 3 ++- tools/regression/bin/sh/expansion/cmdsubst11.0 | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tools/regression/bin/sh/expansion/cmdsubst11.0 diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 9d67b9eeaa28..25793c1672b3 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -140,7 +140,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; @@ -908,6 +908,7 @@ evalcommand(union node *cmd, int flags, 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 000000000000..f1af547421f9 --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst11.0 @@ -0,0 +1,5 @@ +# $FreeBSD$ + +# Not required by POSIX but useful for efficiency. + +[ $$ = $(eval '${SH} -c echo\ \$PPID') ]