From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15696 invoked by alias); 27 Oct 2013 22:31:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31919 Received: (qmail 16466 invoked from network); 27 Oct 2013 22:31:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <131027153133.ZM8059@torch.brasslantern.com> Date: Sun, 27 Oct 2013 15:31:33 -0700 In-reply-to: <20131027211627.79b05e20@pws-pc.ntlworld.com> Comments: In reply to Peter Stephenson "Re: Multio deadlock (Re: multios doesn't work with 2>&1)" (Oct 27, 9:16pm) References: <20131027145917.GA5509@localhost.localdomain> <131027100137.ZM4100@torch.brasslantern.com> <20131027174645.6934d78d@pws-pc.ntlworld.com> <131027112724.ZM16426@torch.brasslantern.com> <131027123917.ZM27930@torch.brasslantern.com> <20131027203347.15be6bc2@pws-pc.ntlworld.com> <20131027211627.79b05e20@pws-pc.ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "Zsh Hackers' List" Subject: Re: Multio deadlock (Re: multios doesn't work with 2>&1) MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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 */