Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH2] Re: avoid closed stdin() in zle widgets
- X-seq: zsh-workers 41272
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Eric Cook <llua@xxxxxxx>
- Subject: [PATCH2] Re: avoid closed stdin() in zle widgets
- Date: Mon, 12 Jun 2017 07:05:54 +0100
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=52DOPZ4dvWTLTstQxeEDJvyHvPRJLHLyOw/Kff06BPM=; b=mPnhgH0nHkMQnLAL2QaOTgKegDdvE7Iy7NWt+5GWGNZBchRNdtvKbdpLZOuyOaIaTz DR4yHxt2oqBJO1oJjoeZc12FvVx7Pe2Z9479v4+kH4K+zJ3s6mVowvLWEgQq0DWupCmp 0bt0B2r8E6uNxsALmSt4HkQi2/AcJs23yO2AQutUbX7Zono5wcBkB/OkQpbUSbgLaQOQ 4kvskbchV+xKcDbX+qmNjyfa3ZHL5INRS1CH7/jFpGeiNDM8cbzrIY0zfhEezL1kSVkx yqgaDe5mT1Uha/T1eJ9gVuNpNXsUYtx/RbrH1zTYTbgNmxj0bLbrO10uVVZKqi9dt8t0 NwMg==
- In-reply-to: <d0c3e336-c186-a5c0-746c-d241a173c189@gmx.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Eric Cook <llua@xxxxxxx>, zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20170611182045.GA5318@chaz.gmail.com> <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));
Messages sorted by:
Reverse Date,
Date,
Thread,
Author