From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20351 invoked by alias); 19 Jan 2015 17:29:16 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19751 Received: (qmail 22186 invoked from network); 19 Jan 2015 17:29:14 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-ad-54bd3ee64012 Date: Mon, 19 Jan 2015 17:28:50 +0000 From: Peter Stephenson To: Zsh Users Subject: Re: warning about closing an already closed file descriptor Message-id: <20150119172850.1bffc197@pwslap01u.europe.root.pri> In-reply-to: <20150119145935.5eee77ee@pwslap01u.europe.root.pri> References: <1469711.vAe1BPIYVt@kdudka.brq.redhat.com> <20150119145935.5eee77ee@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCLMWRmVeSWpSXmKPExsVy+t/xa7rP7PaGGCw6pmux4+RKRgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZVzufM9U0MFX8e7Be9YGxn9cXYycHBICJhK/F01jg7DFJC7c Ww9kc3EICSxllGjff54RwlnEJLFl5UyozDZGiWdLP7CAtLAIqEqs+nyKCcRmEzCUmLppNiOI LSKgKHHm1zewuLCAi8Sd1W+ZQWxeAXuJk4fXsncxcnBwCjhIND50BjGFBHIkns7xAangF9CX uPr3ExPEQfYSM6+cYYToFJT4Mfke2FZmAS2JzduaWCFseYnNayCmCwmoS9y4u5t9AqPQLCQt s5C0zELSsoCReRWjaGppckFxUnquoV5xYm5xaV66XnJ+7iZGSMh+2cG4+JjVIUYBDkYlHl6N nD0hQqyJZcWVuYcYJTiYlUR4A74AhXhTEiurUovy44tKc1KLDzEycXBKNTCuW7w9xMj80lvV zByXuAM/j8+tmnG6ybi/fo6Bif+Zaf/nl6VX9jxJdzjAETdh3zoZh7pwja0RR4S/b+H2suCI TD15zee+zGnGRt0NjH0v+e25F2lKKnLsap3mbOZ3dLrWnCj9Py++plftqn4WX2J7WCGW+4I9 p/a+35Gl4WKPfhlNtlZx6FViKc5INNRiLipOBADVzEEZNwIAAA== On Mon, 19 Jan 2015 14:59:35 +0000 Peter Stephenson 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