From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7047 invoked by alias); 12 Jun 2017 06:06:04 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41272 Received: (qmail 20776 invoked from network); 12 Jun 2017 06:06:03 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr0-f173.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.128.173):SA:0(0.0/5.0):. Processed in 1.652215 secs); 12 Jun 2017 06:06:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.173 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=52DOPZ4dvWTLTstQxeEDJvyHvPRJLHLyOw/Kff06BPM=; b=jXBAVc4SAaZT+WBihsg8fSduYdWQWmkwVbJu9Cnb0P8ul6k+XhFC6+w31FetQdfb1V OR5HB0DhDoTxdXtUhfRRKUL4uV47Fp6mMD9d8gMzqREDzska3egvZX/bum9eAxpQgkgm 9r9GFhsutXMdBqfZ8lIcegLxHo/2EaPhnECJpwe2R+kR21J12ZFgoHDPV97hfl3jljJ5 GTu7Lg6jg035mYvDwnM2ev9nvtsp7L/R731FVB+DdCBQ/LL4S0eqAmRqdjiHqSmepHxd D/zTN/opTFrCFoUHG9GU7Q7RxPZGwONlZHCe/CBG1hQokOJ6RgQBZptA6IMf6GKh2I9a NXow== X-Gm-Message-State: AODbwcBI6GH0pIhDSU0xA5BQMBiEZMu/qnzVw9CnYGvo47bq1y4Bkgx6 LLtvEswd3ZUgiE54 X-Received: by 10.223.142.48 with SMTP id n45mr6245408wrb.188.1497247556988; Sun, 11 Jun 2017 23:05:56 -0700 (PDT) Date: Mon, 12 Jun 2017 07:05:54 +0100 From: Stephane Chazelas To: Eric Cook Cc: zsh-workers@zsh.org Subject: [PATCH2] Re: avoid closed stdin() in zle widgets Message-ID: <20170612060554.GA4709@chaz.gmail.com> Mail-Followup-To: Eric Cook , zsh-workers@zsh.org References: <20170611182045.GA5318@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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));