From c39d2f8e494010030b0c5258f004a38bbb30deee Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 27 Oct 2013 11:27:41 -0700 Subject: 31912: in closemn(), distinguish closing for >&- from closing for a real redirect Fixes knock-on multios bug introduced by workers/20666 way back in 2005. --- ChangeLog | 6 ++++++ Src/exec.c | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8fd52635f..c24084b1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-10-27 Barton E. Schaefer + + * 31912: Src/exec.c: in closemn(), distinguish closing for >&- + from closing for a real redirect. Fixes knock-on multios bug + introduced by workers/20666 way back in 2005. + 2013-10-27 Peter Stephenson * 31909: Jun T: Completion/Unix/Command/_cat: new completion. diff --git a/Src/exec.c b/Src/exec.c index d5fe69ec0..99c7eaa6a 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1967,7 +1967,7 @@ clobber_open(struct redir *f) /**/ static void -closemn(struct multio **mfds, int fd) +closemn(struct multio **mfds, int fd, int type) { if (fd >= 0 && mfds[fd] && mfds[fd]->ct >= 2) { struct multio *mn = mfds[fd]; @@ -2026,7 +2026,7 @@ closemn(struct multio **mfds, int fd) } } _exit(0); - } else if (fd >= 0) + } else if (fd >= 0 && type == REDIR_CLOSE) mfds[fd] = NULL; } @@ -3093,7 +3093,7 @@ execcmd(Estate state, int input, int output, int how, int last1) } } if (fn->fd1 < 10) - closemn(mfds, fn->fd1); + closemn(mfds, fn->fd1, REDIR_CLOSE); if (!closed && zclose(fn->fd1) < 0) { zwarn("failed to close file descriptor %d: %e", fn->fd1, errno); @@ -3102,7 +3102,7 @@ execcmd(Estate state, int input, int output, int how, int last1) case REDIR_MERGEIN: case REDIR_MERGEOUT: if (fn->fd2 < 10) - closemn(mfds, fn->fd2); + closemn(mfds, fn->fd2, fn->type); if (!checkclobberparam(fn)) fil = -1; else if (fn->fd2 > 9 && @@ -3181,7 +3181,7 @@ execcmd(Estate state, int input, int output, int how, int last1) * spawning tee/cat processes as necessary. */ for (i = 0; i < 10; i++) if (mfds[i] && mfds[i]->ct >= 2) - closemn(mfds, i); + closemn(mfds, i, REDIR_CLOSE); if (nullexec) { if (nullexec == 1) { -- cgit 1.4.1