sh: Reduce unnecessary forks with eval.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 21:36:38 +0000 (14:36 -0700)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 21:36:38 +0000 (14:36 -0700)
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

bin/sh/eval.c
tools/regression/bin/sh/expansion/cmdsubst11.0 [new file with mode: 0644]

index 6f0615e..ecc53f4 100644 (file)
@@ -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 <sys/time.h>
@@ -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 (file)
index 0000000..14a3597
--- /dev/null
@@ -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') ]