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

Redirection bug fix



I wrote:
> huyle@xxxxxxxxxxxxxxxxxxxxx reported a bug that:
> > pride% while echo crap >/dev/null; do done
> > ^C
> > pride% echo yes
> >                       <- nothing.  stdout has disappeared.
>
> Help

Actually, it's horribly obvious.  When errflag is set after a return
from addvars(), the shell thinks it was because the addvars() failed
and returns.  However, there was no code there to restore the fd's.
(The first patch was a note to me in case I got too zealous.)

Although it's not necessary here, it might prevent further bugs to
change the `if (unset(NOEXEC)) {' test in execcmd() to 
`if (unset(NOEXEC) && !errflag) {', i.e. if there was an interrupt and
errflag was set, don't try to execute anything at all.  This can't be
wrong and may save some time as well as later blood and tears.

*** Src/exec.c.redir	Wed Jul 10 15:48:17 1996
--- Src/exec.c	Thu Jul 11 14:41:32 1996
***************
*** 1554,1559 ****
--- 1554,1563 ----
  	for (i = 0; i < 10; i++)
  	    if (save[i] != -2)
  		zclose(save[i]);
+ 	/*
+ 	 * Here we specifically *don't* restore the original fd's
+ 	 * before returning.
+ 	 */
  	return;
      }
  
***************
*** 1583,1588 ****
--- 1587,1593 ----
  		if (errflag) {
  		    restore_params(restorelist, removelist);
  		    lastval = 1;
+ 		    fixfds(save);
  		    return;
  		}
  	    }
***************
*** 1653,1658 ****
--- 1658,1664 ----
  		addvars(cmd->vars, 1);
  		if (errflag) {
  		    lastval = 1;
+ 		    fixfds(save);
  		    return;
  		}
  	    }



-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.




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