560f4e
From 4f4fc498361ea9965fde31c36cf9971a92479e9f Mon Sep 17 00:00:00 2001
560f4e
From: Peter Stephenson <pws@zsh.org>
560f4e
Date: Tue, 20 Jan 2015 09:29:22 +0000
560f4e
Subject: [PATCH 1/2] users/19751: remove error on failure to close file
560f4e
 descriptor by number.
560f4e
560f4e
Keep it when closing file descriptor stored in a variable, i.e.
560f4e
explicitly opened by the user.
560f4e
560f4e
Upstream-commit: e6d964246700581fe22ea834b2ea12dd301e8c3d
560f4e
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
560f4e
---
560f4e
 Src/exec.c            |  7 ++++++-
560f4e
 Test/A04redirect.ztst | 10 ++++++----
560f4e
 2 files changed, 12 insertions(+), 5 deletions(-)
560f4e
560f4e
diff --git a/Src/exec.c b/Src/exec.c
560f4e
index 1a4ffe2..fcdc645 100644
560f4e
--- a/Src/exec.c
560f4e
+++ b/Src/exec.c
560f4e
@@ -3075,7 +3075,12 @@ execcmd(Estate state, int input, int output, int how, int last1)
560f4e
 		}
560f4e
 		if (fn->fd1 < 10)
560f4e
 		    closemn(mfds, fn->fd1);
560f4e
-		if (!closed && zclose(fn->fd1) < 0) {
560f4e
+		/*
560f4e
+		 * Only report failures to close file descriptors
560f4e
+		 * if they're under user control as we don't know
560f4e
+		 * what the previous status of others was.
560f4e
+		 */
560f4e
+		if (!closed && zclose(fn->fd1) < 0 && fn->varid) {
560f4e
 		    zwarn("failed to close file descriptor %d: %e",
560f4e
 			  fn->fd1, errno);
560f4e
 		}
560f4e
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
560f4e
index b8086e7..2f21b95 100644
560f4e
--- a/Test/A04redirect.ztst
560f4e
+++ b/Test/A04redirect.ztst
560f4e
@@ -152,11 +152,13 @@
560f4e
 >hello
560f4e
 >goodbye
560f4e
 
560f4e
-  ({ exec 3<&- } 2>/dev/null
560f4e
-  exec 3<&-
560f4e
-  read foo <&-)
560f4e
+  (exec {varid}<&0
560f4e
+  exec {varid}<&-
560f4e
+  print About to close a second time >&2
560f4e
+  read {varid}<&-)
560f4e
 1:'<&-' redirection
560f4e
-*?\(eval\):*: failed to close file descriptor 3:*
560f4e
+?About to close a second time
560f4e
+*?\(eval\):*: failed to close file descriptor *
560f4e
 
560f4e
   print foo >&-
560f4e
 0:'>&-' redirection
560f4e
-- 
560f4e
2.4.0
560f4e
560f4e
560f4e
From 73ea1de52de3f078ef4e6f96ae5042cfe5e79730 Mon Sep 17 00:00:00 2001
560f4e
From: Peter Stephenson <pws@zsh.org>
560f4e
Date: Tue, 20 Jan 2015 11:53:42 +0000
560f4e
Subject: [PATCH 2/2] users/19756: test for case of closing fd with no error
560f4e
 message
560f4e
560f4e
Upstream-commit: 638bfa93a009987e57bd7eaa8b2a1c1067a3652a
560f4e
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
560f4e
---
560f4e
 Test/A04redirect.ztst | 7 ++++++-
560f4e
 1 file changed, 6 insertions(+), 1 deletion(-)
560f4e
560f4e
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
560f4e
index 2f21b95..70c210d 100644
560f4e
--- a/Test/A04redirect.ztst
560f4e
+++ b/Test/A04redirect.ztst
560f4e
@@ -152,11 +152,16 @@
560f4e
 >hello
560f4e
 >goodbye
560f4e
 
560f4e
+  ({exec 3<&- } 2>/dev/null
560f4e
+   exec 3<&-
560f4e
+   read foo <&-)
560f4e
+1:'<&-' redirection with numeric fd (no error message on failure)
560f4e
+
560f4e
   (exec {varid}<&0
560f4e
   exec {varid}<&-
560f4e
   print About to close a second time >&2
560f4e
   read {varid}<&-)
560f4e
-1:'<&-' redirection
560f4e
+1:'<&-' redirection with fd in variable (error message on failure)
560f4e
 ?About to close a second time
560f4e
 *?\(eval\):*: failed to close file descriptor *
560f4e
 
560f4e
-- 
560f4e
2.4.0
560f4e