diff options
author | jilles <jilles@FreeBSD.org> | 2009-06-23 21:50:06 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2009-06-23 21:50:06 +0000 |
commit | fafc9ed68230f653b1e5dfc5425cd3569a1dd707 (patch) | |
tree | 2ae1b77fccb5f328066c5d1b4eb08e0ab23aa987 /bin/sh | |
parent | 4a22bb75d23f761dc88e4dafb643bdbba8e34ba8 (diff) | |
download | FreeBSD-src-fafc9ed68230f653b1e5dfc5425cd3569a1dd707.zip FreeBSD-src-fafc9ed68230f653b1e5dfc5425cd3569a1dd707.tar.gz |
Do not fork for a subshell if it is the last thing this shell is doing
(EV_EXIT). The fork is still done as normal if any traps are active.
In many cases, the fork can be avoided even without this change by using {}
instead of (), but in practice many scripts use (), likely because the
syntax is simpler.
Example:
sh -c '(/bin/sleep 10)& sleep 1;ps -p $! -o comm='
Now prints "sleep" instead of "sh". $! is more useful this way.
Most shells (dash, bash, pdksh, ksh93, zsh) seem to print "sleep" for this.
Example:
sh -c '( ( ( (ps jT))))'
Now shows no waiting shell processes instead of four.
Most shells (dash, bash, pdksh, ksh93, zsh) seem to show zero or one.
PR: bin/74404
Approved by: ed (mentor) (implicit)
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/eval.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index eeea605..c0b2096 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -401,8 +401,8 @@ evalsubshell(union node *n, int flags) int backgnd = (n->type == NBACKGND); expredir(n->nredir.redirect); - jp = makejob(n, 1); - if (forkshell(jp, n, backgnd) == 0) { + if ((!backgnd && flags & EV_EXIT && !have_traps()) || + forkshell(jp = makejob(n, 1), n, backgnd) == 0) { if (backgnd) flags &=~ EV_TESTED; redirect(n->nredir.redirect, 0); |