aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c2
-rw-r--r--shell/msh.c8
2 files changed, 4 insertions, 6 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 3f4610391..8afa15e89 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3243,7 +3243,7 @@ static FILE *generate_stream_from_list(struct pipe *head)
if (pid == 0) { /* child */
if (ENABLE_HUSH_JOB)
die_sleep = 0; /* let nofork's xfuncs die */
- close(channel[0]);
+ close(channel[0]); /* NB: close _first_, then move fd! */
xmove_fd(channel[1], 1);
/* Prevent it from trying to handle ctrl-z etc */
#if ENABLE_HUSH_JOB
diff --git a/shell/msh.c b/shell/msh.c
index 65556043d..fd287f16e 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -2797,15 +2797,13 @@ static int forkexec(struct op *t, int *pin, int *pout, int no_fork, char **wp)
if (!bltin)
export(lookup(cp));
- if (pin) {
+ if (pin) { /* NB: close _first_, then move fds! */
+ close(pin[1]);
xmove_fd(pin[0], 0);
- if (pin[1] != 0)
- close(pin[1]);
}
if (pout) {
+ close(pout[0]);
xmove_fd(pout[1], 1);
- if (pout[0] > 1)
- close(pout[0]);
}
iopp = t->ioact;