From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12952 invoked by alias); 23 Oct 2011 17:19:41 -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: 29844 Received: (qmail 21791 invoked from network); 23 Oct 2011 17:19:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.43 is neither permitted nor denied by SPF record at ntlworld.com) X-ProxyUser-IP: 86.6.29.42 Date: Sun, 23 Oct 2011 18:19:18 +0100 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: 4.3.12-test-2 Message-ID: <20111023181918.1e8f0606@pws-pc.ntlworld.com> In-Reply-To: <20111021120848.252c5811@pwslap01u.europe.root.pri> References: <20111020213929.410073fe@pws-pc.ntlworld.com> <20111021102007.GB23272@redoubt.spodhuis.org> <20111021120848.252c5811@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.7.9 (GTK+ 2.24.4; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 21 Oct 2011 12:08:48 +0100 Peter Stephenson wrote: > > /home/phil/.zshenv:133: failed to close file descriptor 1: bad file descriptor > > Hmm... I'm getting an error from closing stdout (just once), too. That > doesn't seem right and needs looking into. Possibly the error is > failing to close it, rather than the new error message (which is > deliberate if the shell fails to do an operation on file descriptors > you've explicitly asked for), so the real problem may not be new. It looks like there isn't really a problem, apart from the error: we were attempting to close an fd that had already been closed, which would have caused a system error but not actually done any damage. This stops the error. Could do with a test. I got a bit worried about why we'd be moving the fd rather than just closing it completely in the case of exec (which was showing up the same error), but there's a special case later on for an exec that's just doing redirections where we close the saved fd --- a bit baroque, but presumably OK. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.204 diff -p -u -r1.204 exec.c --- Src/exec.c 28 Aug 2011 16:38:28 -0000 1.204 +++ Src/exec.c 23 Oct 2011 17:15:05 -0000 @@ -2912,6 +2912,7 @@ execcmd(Estate state, int input, int out } addfd(forked, save, mfds, fn->fd1, fn->fd2, 1, fn->varid); } else { + int closed; if (fn->type != REDIR_HERESTR && xpandredir(fn, redir)) continue; if (errflag) { @@ -3002,11 +3003,20 @@ execcmd(Estate state, int input, int out * Note we may attempt to close an fd beyond max_zsh_fd: * OK as long as we never look in fdtable for it. */ - if (!forked && fn->fd1 < 10 && save[fn->fd1] == -2) + closed = 0; + if (!forked && fn->fd1 < 10 && save[fn->fd1] == -2) { save[fn->fd1] = movefd(fn->fd1); + if (save[fn->fd1] >= 0) { + /* + * The original fd is now closed, we don't need + * to do it below. + */ + closed = 1; + } + } if (fn->fd1 < 10) closemn(mfds, fn->fd1); - if (zclose(fn->fd1) < 0) { + if (!closed && zclose(fn->fd1) < 0) { zwarn("failed to close file descriptor %d: %e", fn->fd1, errno); } -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/