zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: multios doesn't work with 2>&1
Date: Sun, 27 Oct 2013 11:11:50 -0700	[thread overview]
Message-ID: <131027111150.ZM16293@torch.brasslantern.com> (raw)
In-Reply-To: <131027100137.ZM4100@torch.brasslantern.com>

[> workers]

On Oct 27, 10:01am, Bart Schaefer wrote:
}
} }     % echo foo 2>&1 >/dev/null | sed 's/foo/bar/'
} } 
} } should output "bar" if multios has been set. But it outputs nothing
} 
} If there's a way to fix the original complaint (that >&- doesn't really
} close the descriptor when a multio is involved, so unnecessary multios
} result) without the above example remaining broken, I may need some help
} to find it.

Turns out I didn't need help after all.

As usual, it's just a matter of passing around enough information.


diff --git a/Src/exec.c b/Src/exec.c
index d5fe69e..99c7eaa 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) {


      parent reply	other threads:[~2013-10-27 18:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20131027145917.GA5509@localhost.localdomain>
     [not found] ` <131027100137.ZM4100@torch.brasslantern.com>
2013-10-27 17:46   ` Peter Stephenson
2013-10-27 18:27     ` Bart Schaefer
2013-10-27 19:39       ` Multio deadlock (Re: multios doesn't work with 2>&1) Bart Schaefer
2013-10-27 20:24         ` Bart Schaefer
2013-10-27 20:33         ` Peter Stephenson
2013-10-27 21:16           ` Peter Stephenson
2013-10-27 22:31             ` Bart Schaefer
2013-10-27 22:18           ` Bart Schaefer
2013-10-27 18:11   ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=131027111150.ZM16293@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).