From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9486 invoked by alias); 16 Jul 2013 20:56:06 -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: 31521 Received: (qmail 20283 invoked from network); 16 Jul 2013 20:55:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.215.170 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-proxyuser-ip:date:from:to:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=aFFD0fm9ZBxokiJCscl1I6tMWTbjshuE/HVpuYTXaDQ=; b=MwfSmnsMTmPbmRSks2GeZ+zAT5jf/BWtQfMMLD1MonxflRaJGJgcRso3JTPo4lUzCF XlDi6sHhoWQVhzJwLno2ZaOwG5y/lvULO/10v8KuFQVhAIzGExgaL/cVGB9J6PWDmla+ 606JdD6kKMywUMAIC1RTCixE6APL2gogn7IKYy1/nmArjEae9q9H7LpSOCCtZynTVxDD gNoCHiHcn7F+1q9h+lC5DL/j4jOfwMqxWFaOqlBiGQZwp4gBcfo4b0os/IU1EN9fNWDx fqmMuFbidqqGxgzGThjnOqF09/3lbYi3zWK6rFB2t9FagO8DykUdW0/x1bEgcjvBJ/WA 2C/Q== X-Received: by 10.14.203.194 with SMTP id f42mr3341390eeo.53.1374008144801; Tue, 16 Jul 2013 13:55:44 -0700 (PDT) X-ProxyUser-IP: 86.6.30.159 Date: Tue, 16 Jul 2013 21:55:40 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: bug with eval, proc-subst and pipes Message-ID: <20130716215540.22d88a27@pws-pc.ntlworld.com> In-Reply-To: <130715100624.ZM14123@torch.brasslantern.com> References: <20130715133525.GA7694@chaz.gmail.com> <130715100624.ZM14123@torch.brasslantern.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkCg0sYji1P7XPlgcwGJ96kIbguE0LmC7ksPFK+tXo8gWXFdun2siC5+lyRm/ICIk4wEcjh On Mon, 15 Jul 2013 10:06:24 -0700 Bart Schaefer wrote: > On Jul 15, 2:35pm, Stephane Chazelas wrote: > } Subject: bug with eval, proc-subst and pipes > } > } NOK$ eval 'paste <(echo 1) <(echo 2) <(echo 3) <(echo 4)' | cat > } paste: /proc/self/fd/13: No such file or directory > > It's a race condition of some kind. I can reproduce reliably with > > % (){ sleep 5; paste "$@" } <(echo 1) > > even without an "eval". That's not a race; it looks like it because it relies on a command running before the one that's using the command substitution, but in fact the bug in this case is completely deterministic. It may therefore be a different problem from Stephane's. The shell executes the () { ... }; it creates fd 11 (in this case, the first beyond 10 which is SHTTY). It marks it in the global fdtable array as FDT_PROC_SUBST. Now it starts executing inside the anonymous function. It starts processing the sleep and gets to the chunk in execcmd() where it handles the fork. At line 2864 of exec.c, as it's in the function that's calling sleep, it closes all the file descriptors of type FDT_PROC_SUBST that it thinks are private to the sleep. Unfortunately as fdtable is global it has no way of knowing that actually fd 11 is associated with the current function, not the sleep, so it closes it anyway. So when it gets to the paste fd 11 is already closed. I suppose a smarter way of marking such file descriptors is needed, perhaps one associated with the appropriate job in the same way as auxiliary processes are remembered. Good luck avoiding leaks... -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/