From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6247 invoked by alias); 20 Jul 2013 23:03:22 -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: 31549 Received: (qmail 11347 invoked from network); 20 Jul 2013 23:03:16 -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.174 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=oqInbLc+9aKWzFCQxz7XYB9SzVK6dR4WZ6o8MnB6qkM=; b=EkHHK+YLIhX0Pw125X0IWb2oRvJiHtYnceW+lVCvS1FJLtI5qqwQaU6n+qgzoTdapv FGfR2ZHiP196uKMrmPteeN8m2tnU2WL6DwEqJmrnwsffZeADQsDpVapg2w1ChmGMUIQn HKM9+VlHvMFiMxnaLiViUi3m5T4FIh8YDKFwKgPCC0T4jWUNOiJydEGvdvFoxCBXPvMg 1iMhj/6qawMghp+UoGbiMFPRNxcAQT6cCVROCV/nvy6x7aShwtDAzVaCDUEyXjl011fF GLEZX3YY9ROBqZQtXb5Cl53sLBuSwMIuDsWZXtvqlTtp/ZmwuuORuaq0ynH3IFYogST5 jLug== X-Received: by 10.15.35.65 with SMTP id f41mr12063316eev.61.1374360905014; Sat, 20 Jul 2013 15:55:05 -0700 (PDT) X-ProxyUser-IP: 86.6.30.159 Date: Sat, 20 Jul 2013 23:55:01 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: bug with eval, proc-subst and pipes Message-ID: <20130720235501.45a9e179@pws-pc.ntlworld.com> In-Reply-To: <20130720202531.GA10442@chaz.gmail.com> References: <20130716215540.22d88a27@pws-pc.ntlworld.com> <130717000027.ZM15643@torch.brasslantern.com> <20130717201733.2c0b029b@pws-pc.ntlworld.com> <20130718095741.3f54725f@pwslap01u.europe.root.pri> <20130718102227.527429bd@pwslap01u.europe.root.pri> <20130718123210.054f1ea1@pwslap01u.europe.root.pri> <20130719200159.GA8712@chaz.gmail.com> <20130719205853.GB8712@chaz.gmail.com> <20130720181144.1b5a7fc0@pws-pc.ntlworld.com> <20130720202531.GA10442@chaz.gmail.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: ALoCoQloWsKIFqGIMf5U8yLxzdl066DK90vqYzok0AJ0xkNixIwOjcUlvgzxd4fV0o+sMhaL2Dyq On Sat, 20 Jul 2013 21:25:31 +0100 Stephane Chazelas wrote: > It's better: > > $ eval 'ls -l <(echo 1) <(echo 2) <(echo 3) <(echo 4)' | cat > ls: cannot access /proc/self/fd/11: No such file or directory > lr-x------ 1 chazelas chazelas 64 Jul 20 21:23 /proc/self/fd/10 -> pipe:[1541173] > lr-x------ 1 chazelas chazelas 64 Jul 20 21:23 /proc/self/fd/12 -> pipe:[1541175] > lr-x------ 1 chazelas chazelas 64 Jul 20 21:23 /proc/self/fd/13 -> pipe:[1541176] > > Only one now instead of two. OK, getting somewhere... In that case, your previous mail suggests zclose(subsh_close) is the other thing that needs looking at. It seems to me that subsh_close is liable to the same problem as I (eventually) fixed in the example Bart came up with. Any chance the following patch resolves the issue? (I checked and there shouldn't be any work for Vincent this time round...) One of the lines I removed, - if (subsh_close >= 0 && fdtable[subsh_close] == FDT_UNUSED) - subsh_close = -1; suggests we might be on the right track here... at some point, someone was obviously worried that subsh_close might already have been closed, and if that's the case it's entirely possible that it was also reopened for a different purpose, which would be what you're seeing. Paranoid note: the traditional problem with associating new things with jobs, as addfilelist() does, is you find out there isn't a job because it's been optimised out. However, I believe that by the time we've got as far as execpline2() the case is sufficiently complicated it must have a job. (Ultra paranoid note: in which case we *must* ensure the job is cleared up, right? There's no possibility of a file descriptor leak?) (If you understood that I will endorse your Unix experience on LinkedIn...) diff --git a/Src/exec.c b/Src/exec.c index f9efb3a..1c44565 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1653,8 +1653,6 @@ execpline(Estate state, wordcode slcode, int how, int last1) return lastval; } -static int subsh_close = -1; - /* execute pipeline. This function assumes the `pline' is not NULL. */ /**/ @@ -1731,7 +1729,7 @@ execpline2(Estate state, wordcode pcode, } } else { /* otherwise just do the pipeline normally. */ - subsh_close = pipes[0]; + addfilelist(NULL, pipes[0]); execcmd(state, input, pipes[1], how, 0); } zclose(pipes[1]); @@ -1744,8 +1742,6 @@ execpline2(Estate state, wordcode pcode, execpline2(state, *state->pc++, how, pipes[0], output, last1); list_pipe = old_list_pipe; cmdpop(); - zclose(pipes[0]); - subsh_close = -1; } } @@ -2162,8 +2158,6 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag, mfds[fd1]->fds[mfds[fd1]->ct++] = fdN; } } - if (subsh_close >= 0 && fdtable[subsh_close] == FDT_UNUSED) - subsh_close = -1; } /**/ @@ -3245,11 +3239,6 @@ execcmd(Estate state, int input, int output, int how, int last1) if (is_shfunc) { /* It's a shell function */ - - if (subsh_close >= 0) - zclose(subsh_close); - subsh_close = -1; - execshfunc((Shfunc) hn, args); } else { /* It's a builtin */ @@ -3325,9 +3314,6 @@ execcmd(Estate state, int input, int output, int how, int last1) DPUTS(varspc, "BUG: assignment before complex command"); list_pipe = 0; - if (subsh_close >= 0) - zclose(subsh_close); - subsh_close = -1; /* If we're forked (and we should be), no need to return */ DPUTS(last1 != 1 && !forked, "BUG: not exiting?"); DPUTS(type != WC_SUBSH, "Not sure what we're doing."); @@ -5069,7 +5055,6 @@ execsave(void) es->trapisfunc = trapisfunc; es->traplocallevel = traplocallevel; es->noerrs = noerrs; - es->subsh_close = subsh_close; es->underscore = ztrdup(zunderscore); es->next = exstack; exstack = es; @@ -5100,7 +5085,6 @@ execrestore(void) trapisfunc = exstack->trapisfunc; traplocallevel = exstack->traplocallevel; noerrs = exstack->noerrs; - subsh_close = exstack->subsh_close; setunderscore(exstack->underscore); zsfree(exstack->underscore); en = exstack->next; diff --git a/Src/zsh.h b/Src/zsh.h index ebd3cb7..d7b130c 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -977,7 +977,6 @@ struct execstack { int trapisfunc; int traplocallevel; int noerrs; - int subsh_close; char *underscore; }; -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/