From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id MAA02053 for ; Sat, 3 Aug 1996 12:52:12 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id WAA01063; Fri, 2 Aug 1996 22:40:11 -0400 (EDT) Resent-Date: Fri, 2 Aug 1996 22:40:11 -0400 (EDT) From: Zoltan Hidvegi Message-Id: <199608030239.EAA00458@bolyai.cs.elte.hu> Subject: Re: Function output re-direction To: acs@world.std.com Date: Sat, 3 Aug 1996 04:39:06 +0200 (MET DST) Cc: zsh-workers@math.gatech.edu In-Reply-To: <199608021842.OAA07896@spacely.icd.teradyne.com> from Vinnie Shelton at "Aug 2, 96 02:42:28 pm" Organization: Dept. of Comp. Sci., Eotvos University, Budapest, Hungary Phone: (36 1)2669833 ext: 2667, home phone: (36 1) 2752368 X-Mailer: ELM [version 2.4ME+ PL16 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"WlXqg2.0.XG.Bmh0o"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1909 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > I've stumbled across a rather bad bug in pre5. I haven't applied any of the > patches yet, so if this has already been fixed, feel free to ignore this > message. When I pipe input to a shell function and re-direct the output, > stdout of the shell is re-directed as well: > > spacely% zsh -f > spacely% echo $ZSH_VERSION > 3.0-pre5 > spacely% function x { > > echo x > > } > spacely% x > x # OK so far > spacely% ls | x >/dev/null > spacely% ls # Output is gone! > spacely% exec >/dev/tty # got it back This is fixed by the patch below but I'm not really pleased with that patch. The problem was that addfd() closed subsh_close (moved it to the input of the x function). Then the redirection daved the stdout and it replaced the just closed subsh_close and later a zclose(subsh_close) was executed which closed the original stdout forever. I'm not pleased with that because I do not really understand this subsh_close variable and I do not like it because it is a static variable which may be changed by a trap function. To avoid that I added it to execstack. Zoltan *** Src/exec.c 1996/08/02 13:37:11 2.79 --- Src/exec.c 1996/08/03 02:34:47 *************** *** 1025,1030 **** --- 1025,1032 ---- } else /* add another fd to an already split stream */ mfds[fd1]->fds[mfds[fd1]->ct++] = movefd(fd2); } + if (!fdtable[subsh_close]) + subsh_close = -1; } /**/ *************** *** 2650,2655 **** --- 2652,2658 ---- es->cmdoutval = cmdoutval; es->trapreturn = trapreturn; es->noerrs = noerrs; + es->subsh_close = subsh_close; es->next = exstack; exstack = es; noerrs = cmdoutpid = 0; *************** *** 2677,2682 **** --- 2680,2686 ---- cmdoutval = exstack->cmdoutval; trapreturn = exstack->trapreturn; noerrs = exstack->noerrs; + subsh_close = exstack->subsh_close; en = exstack->next; free(exstack); exstack = en; *** Src/zsh.h 1996/07/31 15:45:25 2.40 --- Src/zsh.h 1996/07/31 13:40:59 *************** *** 606,611 **** --- 606,612 ---- int cmdoutval; int trapreturn; int noerrs; + int subsh_close; }; struct heredocs {