zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] avoid closed stdin() in zle widgets
@ 2017-06-11 18:20 Stephane Chazelas
  2017-06-12  4:15 ` Eric Cook
  0 siblings, 1 reply; 12+ messages in thread
From: Stephane Chazelas @ 2017-06-11 18:20 UTC (permalink / raw)
  To: Zsh hackers list

Hello,

in zle widgets, stdin currently appears to be closed. That's
generally not a good idea to close fds 0, 1, 2 as many commands
are confused when the files they open suddenly become their
stdin/stdout/stderr because the first free fd is 0/1/2.

See

https://unix.stackexchange.com/q/370475

for instance.

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 81687c7..0e26da3 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -2012,7 +2012,8 @@ enditem()
 Attribute flags that transform the final value (tt(-L), tt(-R), tt(-Z),
 tt(-l), tt(-u)) are only applied to the expanded value at the point
 of a parameter expansion expression using `tt($)'.  They are not applied
-when a parameter is retrieved internally by the shell for any purpose. 
+when a parameter is retrieved internally by the shell for any purpose.
+They have no effect on array or associative array parameters.
 
 The following attribute flags may be specified:
 
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 6c271b5..be2b062 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1485,6 +1485,13 @@ execzlefunc(Thingy func, char **args, int set_bindk)
 	    int inuse = w->flags & WIDGET_INUSE;
 	    w->flags |= WIDGET_INUSE;
 
+	    if (osi > 0) {
+		/*
+		 * Many commands don't like having a closed stdin, open on
+		 * /dev/null instead
+		 */
+		open("/dev/null", O_RDWR | O_NOCTTY); /* ignore failure */
+	    }
 	    if (*args) {
 		largs = newlinklist();
 		addlinknode(largs, dupstring(w->u.fnnam));


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-06-17  3:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-11 18:20 [PATCH] avoid closed stdin() in zle widgets Stephane Chazelas
2017-06-12  4:15 ` Eric Cook
2017-06-12  6:05   ` [PATCH2] " Stephane Chazelas
2017-06-12 14:34     ` Daniel Shahaf
2017-06-12 15:10       ` Stephane Chazelas
2017-06-12 15:19         ` [PATCH3] " Stephane Chazelas
2017-06-12 15:34           ` Daniel Shahaf
2017-06-12 16:09             ` Bart Schaefer
2017-06-12 19:02               ` Stephane Chazelas
2017-06-14 22:44                 ` Bart Schaefer
2017-06-15  8:42                   ` Stephane Chazelas
2017-06-17  3:03                     ` Bart Schaefer

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).