From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: warning about closing an already closed file descriptor
Date: Mon, 19 Jan 2015 17:28:50 +0000 [thread overview]
Message-ID: <20150119172850.1bffc197@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20150119145935.5eee77ee@pwslap01u.europe.root.pri>
On Mon, 19 Jan 2015 14:59:35 +0000
Peter Stephenson <p.stephenson@samsung.com> wrote:
> The problem that change fixed wasn't really intended to have a visible
> effect, apart from closing f.d.s the shell didn't know about. If it's
> more useful without the message than with it, it can be removed.
>...
> We can special case the {varid}<&- syntax --- that might be useful since
> it implies the user was previously in direct control of the f.d. so is
> ikely to be interested in an error if closing it failed.
This easy patch does that. Is anyone other than Kamil interested enough
to comment?
pws
diff --git a/Src/exec.c b/Src/exec.c
index f42fb2b..3b0e936 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3203,7 +3203,12 @@ execcmd(Estate state, int input, int output, int how, int last1)
}
if (fn->fd1 < 10)
closemn(mfds, fn->fd1, REDIR_CLOSE);
- if (!closed && zclose(fn->fd1) < 0) {
+ /*
+ * Only report failures to close file descriptors
+ * if they're under user control as we don't know
+ * what the previous status of others was.
+ */
+ if (!closed && zclose(fn->fd1) < 0 && fn->varid) {
zwarn("failed to close file descriptor %d: %e",
fn->fd1, errno);
}
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index a39ce46..cb67788 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -152,11 +152,13 @@
>hello
>goodbye
- ({ exec 3<&- } 2>/dev/null
- exec 3<&-
- read foo <&-)
+ (exec {varid}<&0
+ exec {varid}<&-
+ print About to close a second time >&2
+ read {varid}<&-)
1:'<&-' redirection
-*?\(eval\):*: failed to close file descriptor 3:*
+?About to close a second time
+*?\(eval\):*: failed to close file descriptor *
print foo >&-
0:'>&-' redirection
next prev parent reply other threads:[~2015-01-19 17:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-19 13:33 Kamil Dudka
2015-01-19 14:59 ` Peter Stephenson
2015-01-19 17:28 ` Peter Stephenson [this message]
2015-01-20 9:36 ` Kamil Dudka
2015-01-20 11:02 ` Roman Neuhauser
2015-01-20 11:39 ` Peter Stephenson
2015-01-20 11:43 ` Roman Neuhauser
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=20150119172850.1bffc197@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-users@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).