diff options
| author | martin <martin@NetBSD.org> | 2019-12-26 20:16:47 +0000 |
|---|---|---|
| committer | martin <martin@NetBSD.org> | 2019-12-26 20:16:47 +0000 |
| commit | 3983b18f22f1c16ddbdd87696627dfca0cf54601 (patch) | |
| tree | 517529bd288595e1b607b2460d4d4071fe80ab3d /bin | |
| parent | fccdcbe34e6b9673b6cfdbc779320188e065199e (diff) | |
Pull up following revision(s) (requested by kre in ticket #582):
bin/sh/eval.c: revision 1.177
Use fork() rather than vfork() when forking to run a background
process with redirects. If we use vfork() and a redirect hangs
(eg: opening a fifo) which the parent was intended to unhang,
then the parent never gets to continue to unhang the child.
eg: mkfifo f; cat <f &; echo foo>f
The parent should not be waiting for a background process, even
just for its exec() to complete. if there are no redirects there
is (should be) nothing left that might be done that will cause any
noticeable delay, so vfork() should be safe in all other cases.
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/eval.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 0ce1e79b040..1a227c75eaf 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.175.2.1 2019/12/11 14:52:50 martin Exp $ */ +/* $NetBSD: eval.c,v 1.175.2.2 2019/12/26 20:16:47 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.175.2.1 2019/12/11 14:52:50 martin Exp $"); +__RCSID("$NetBSD: eval.c,v 1.175.2.2 2019/12/26 20:16:47 martin Exp $"); #endif #endif /* not lint */ @@ -552,8 +552,8 @@ evalsubshell(union node *n, int flags) forkshell(jp = makejob(n, 1), n, backgnd?FORK_BG:FORK_FG) == 0) { if (backgnd) flags &=~ EV_TESTED; - redirect(n->nredir.redirect, REDIR_KEEP); INTON; + redirect(n->nredir.redirect, REDIR_KEEP); evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */ } else if (backgnd) exitstatus = 0; @@ -1086,7 +1086,8 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd) * child's address space is actually shared with the parent as * we rely on this. */ - if (usefork == 0 && cmdentry.cmdtype == CMDNORMAL) { + if (usefork == 0 && cmdentry.cmdtype == CMDNORMAL && + (!cmd->ncmd.backgnd || cmd->ncmd.redirect == NULL)) { pid_t pid; int serrno; |
