From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Eric Cook <llua@gmx.com>
Cc: zsh-workers@zsh.org
Subject: [PATCH2] Re: avoid closed stdin() in zle widgets
Date: Mon, 12 Jun 2017 07:05:54 +0100 [thread overview]
Message-ID: <20170612060554.GA4709@chaz.gmail.com> (raw)
In-Reply-To: <d0c3e336-c186-a5c0-746c-d241a173c189@gmx.com>
2017-06-12 00:15:20 -0400, Eric Cook:
[...]
> > 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.
[...]
> It is documented to work like that in zshzle
[...]
Well spotted. Thanks. (I also left a diff by mistake for an
unrelated issue discussed earlier on. Sorry about that).
New patch:
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index b65e3be..bd0252f 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -750,12 +750,12 @@ sect(User-Defined Widgets)
cindex(widgets, user-defined)
User-defined widgets, being implemented as shell functions,
can execute any normal shell command. They can also run other widgets
-(whether built-in or user-defined) using the tt(zle) builtin command.
-The standard input of the function is closed to prevent external commands
-from unintentionally blocking ZLE by reading from the terminal, but
-tt(read -k) or tt(read -q) can be used to read characters. Finally,
-they can examine and edit the ZLE buffer being edited by
-reading and setting the special parameters described below.
+(whether built-in or user-defined) using the tt(zle) builtin command. The
+standard input of the function is redirected from /dev/null to prevent
+external commands from unintentionally blocking ZLE by reading from the
+terminal, but tt(read -k) or tt(read -q) can be used to read characters.
+Finally, they can examine and edit the ZLE buffer being edited by reading
+and setting the special parameters described below.
cindex(parameters, editor)
cindex(parameters, zle)
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));
next prev parent reply other threads:[~2017-06-12 6:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-11 18:20 [PATCH] " Stephane Chazelas
2017-06-12 4:15 ` Eric Cook
2017-06-12 6:05 ` Stephane Chazelas [this message]
2017-06-12 14:34 ` [PATCH2] " 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
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=20170612060554.GA4709@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=llua@gmx.com \
--cc=zsh-workers@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).