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

Re: [zsh 3.0.0 bug] <command> | <builtin> <redirection>



> Standard input is closed when the redirection in the above
> command template fails.
> 
> Example:
> 
> algo% zsh -f
> algo% tty
> /dev/ttyq12
> algo% : | : > /
> zsh: invalid argument: /
> algo% tty
> not a tty

It's worse:

hzoli% : < / > foo 2> /
zsh: is a directory: /
hzoli% echo foo
zsh: write error: bad file number

The fix is below.

Zoltan

*** exec.c	1996/12/11 02:27:28	3.1.0.5
--- exec.c	1996/12/14 02:41:28
***************
*** 31,38 ****
  
  #include "zsh.h"
  
! #define execerr() { if (forked) _exit(1); \
! 	closemnodes(mfds); lastval = 1; return; }
  
  static LinkList args;
  static int doneps4;
--- 31,38 ----
  
  #include "zsh.h"
  
! #define execerr() if (!forked) { lastval = 1; return; } else _exit(1)
! 	
  
  static LinkList args;
  static int doneps4;
***************
*** 1483,1494 ****
--- 1483,1496 ----
  	      "BUG: unexpanded here document\n");
  	if (fn->type == INPIPE) {
  	    if (fn->fd2 == -1) {
+ 		closemnodes(mfds);
  		fixfds(save);
  		execerr();
  	    }
  	    addfd(forked, save, mfds, fn->fd1, fn->fd2, 0);
  	} else if (fn->type == OUTPIPE) {
  	    if (fn->fd2 == -1) {
+ 		closemnodes(mfds);
  		fixfds(save);
  		execerr();
  	    }
***************
*** 1497,1502 ****
--- 1499,1505 ----
  	    if (fn->type != HERESTR && xpandredir(fn, cmd->redir))
  		continue;
  	    if (errflag) {
+ 		closemnodes(mfds);
  		fixfds(save);
  		execerr();
  	    }
***************
*** 1504,1509 ****
--- 1507,1513 ----
  	    case HERESTR:
  		fil = getherestr(fn);
  		if (fil == -1) {
+ 		    closemnodes(mfds);
  		    fixfds(save);
  		    if (errno != EINTR)
  			zerr("%e", NULL, errno);
***************
*** 1518,1523 ****
--- 1522,1528 ----
  		else
  		    fil = open(unmeta(fn->name), O_RDWR | O_CREAT, 0666);
  		if (fil == -1) {
+ 		    closemnodes(mfds);
  		    fixfds(save);
  		    if (errno != EINTR)
  			zerr("%e: %s", fn->name, errno);
***************
*** 1543,1548 ****
--- 1548,1554 ----
  		if (fil == -1) {
  		    char fdstr[4];
  
+ 		    closemnodes(mfds);
  		    fixfds(save);
  		    sprintf(fdstr, "%d", fn->fd2);
  		    zerr("%s: %e", fdstr, errno);
***************
*** 1564,1569 ****
--- 1570,1576 ----
  		if (fil == -1 || dfil == -1) {
  		    if(fil != -1)
  			close(fil);
+ 		    closemnodes(mfds);
  		    fixfds(save);
  		    if (errno != EINTR)
  			zerr("%e: %s", fn->name, errno);



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