zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: 4.3.12-test-2
Date: Sun, 23 Oct 2011 18:19:18 +0100	[thread overview]
Message-ID: <20111023181918.1e8f0606@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20111021120848.252c5811@pwslap01u.europe.root.pri>

On Fri, 21 Oct 2011 12:08:48 +0100
Peter Stephenson <Peter.Stephenson@csr.com> 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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2011-10-23 17:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20111020213929.410073fe@pws-pc.ntlworld.com>
     [not found] ` <20111021102007.GB23272@redoubt.spodhuis.org>
2011-10-21 11:08   ` 4.3.12-test-2 Peter Stephenson
2011-10-23 17:19     ` Peter Stephenson [this message]
2011-10-23 17:48       ` 4.3.12-test-2 Peter Stephenson

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=20111023181918.1e8f0606@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).