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