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

Re: multios and unnecessary processes



On Jan 10,  5:11pm, Stephane Chazelas wrote:
} Subject: Re: multios and unnecessary processes
}
} However to get back to my initial statement, don't you agree
} it's a problem that
} 
} cmd >&2 >&- >&2
} 
} doesn't redirect stdout to stderr but to a pipe to a background
} process that just echos the output to stderr?

Yes, that could be considered a bug.  Suggested patch below.

But under what circumstances would you write that?

The only case where I can think offhand of that coming up is something
like this:

  original_cmd="lsof -ag $$ -d 0-2,10-15 >&2"
  # ... time and code passes ...
  modified_cmd="$original_cmd >&-"
  # ... more time and code passes ...
  finished_cmd="$modified_cmd >&2"
  eval $finished_cmd

Here's the patch.  This relies on the fact that mfds[] elements are heap
allocated; it also means that repeatedly opening and closing a descriptor
with MULTIOS on will repeatedly allocate and discard a multio structure,
whereas before it would re-use it even after closing.

Patch line numbers may be off because I've applied 20632 (PWS, I think
you could commit that, it seems to be fine).

Index: Src/exec.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/exec.c,v
retrieving revision 1.22
diff -c -r1.22 exec.c
--- exec.c	6 Dec 2004 16:51:18 -0000	1.22
+++ exec.c	10 Jan 2005 19:08:51 -0000
@@ -1487,6 +1488,7 @@
 	}
 	_exit(0);
     }
+    mfds[fd] = NULL;
 }
 
 /* close all the mnodes (failure) */



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