zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: Multio deadlock (Re: multios doesn't work with 2>&1)
Date: Sun, 27 Oct 2013 15:31:33 -0700	[thread overview]
Message-ID: <131027153133.ZM8059@torch.brasslantern.com> (raw)
In-Reply-To: <20131027211627.79b05e20@pws-pc.ntlworld.com>

On Oct 27,  9:16pm, Peter Stephenson wrote:
} Subject: Re: Multio deadlock (Re: multios doesn't work with 2>&1)
}
} Er, because it doesn't mean that, FDT_INTERNAL means "users can't
} monkey with this".

See my other message RE asymmetry of movefd/redup.

} We need something to mean "open and users can monkey with it".

Except that obviously FDT_INTERNAL doesn't really prevent user monkeying,
because fdtable[0..2] spend a lot of time in FDT_INTERNAL state without
breaking any redirections.  So either users could in fact monkey with an
FDT_INTERNAL fd if they were able to guess the FD number, or the monkeying
is barred some other way.

In any case this patch finally does seem to resolve the deadlock in a
safe manner; it can't have been correct that those dup() calls could be
allowed to return an FD in 0..2 range.

I threw in the init.c bit just for completeness, as mentioned that state
is rapidly stomped on if any redirections of 0..2 are done.

diff --git a/Src/exec.c b/Src/exec.c
index 99c7eaa..df915e1 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3123,7 +3123,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		    int fd = fn->fd2;
 		    if(fd == -2)
 			fd = (fn->type == REDIR_MERGEOUT) ? coprocout : coprocin;
-		    fil = dup(fd);
+		    fil = movefd(dup(fd));
 		}
 		if (fil == -1) {
 		    char fdstr[4];
@@ -3151,7 +3151,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		else
 		    fil = clobber_open(fn);
 		if(fil != -1 && IS_ERROR_REDIR(fn->type))
-		    dfil = dup(fil);
+		    dfil = movefd(dup(fil));
 		else
 		    dfil = 0;
 		if (fil == -1 || dfil == -1) {
diff --git a/Src/init.c b/Src/init.c
index 01a969d..7032ff8 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1584,6 +1584,7 @@ zsh_main(UNUSED(int argc), char **argv)
 
     fdtable_size = zopenmax();
     fdtable = zshcalloc(fdtable_size*sizeof(*fdtable));
+    fdtable[0] = fdtable[1] = fdtable[2] = FDT_EXTERNAL;
 
     createoptiontable();
     emulate(zsh_name, 1, &emulation, opts);   /* initialises most options */


  reply	other threads:[~2013-10-27 22:31 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   ` multios doesn't work with 2>&1 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 [this message]
2013-10-27 22:18           ` Bart Schaefer
2013-10-27 18:11   ` multios doesn't work with 2>&1 Bart Schaefer

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=131027153133.ZM8059@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).