Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Function output re-direction



> 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 {



Messages sorted by: Reverse Date, Date, Thread, Author