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

Re: Multio deadlock (Re: multios doesn't work with 2>&1)



On Oct 27,  9:16pm, Peter Stephenson wrote:
} Subject: Re: Multio deadlock (Re: multios doesn't work with 2>&1)
}
} Er, because it doesn't mean that, FDT_INTERNAL means "users can't
} monkey with this".

See my other message RE asymmetry of movefd/redup.

} We need something to mean "open and users can monkey with it".

Except that obviously FDT_INTERNAL doesn't really prevent user monkeying,
because fdtable[0..2] spend a lot of time in FDT_INTERNAL state without
breaking any redirections.  So either users could in fact monkey with an
FDT_INTERNAL fd if they were able to guess the FD number, or the monkeying
is barred some other way.

In any case this patch finally does seem to resolve the deadlock in a
safe manner; it can't have been correct that those dup() calls could be
allowed to return an FD in 0..2 range.

I threw in the init.c bit just for completeness, as mentioned that state
is rapidly stomped on if any redirections of 0..2 are done.

diff --git a/Src/exec.c b/Src/exec.c
index 99c7eaa..df915e1 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3123,7 +3123,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		    int fd = fn->fd2;
 		    if(fd == -2)
 			fd = (fn->type == REDIR_MERGEOUT) ? coprocout : coprocin;
-		    fil = dup(fd);
+		    fil = movefd(dup(fd));
 		}
 		if (fil == -1) {
 		    char fdstr[4];
@@ -3151,7 +3151,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		else
 		    fil = clobber_open(fn);
 		if(fil != -1 && IS_ERROR_REDIR(fn->type))
-		    dfil = dup(fil);
+		    dfil = movefd(dup(fil));
 		else
 		    dfil = 0;
 		if (fil == -1 || dfil == -1) {
diff --git a/Src/init.c b/Src/init.c
index 01a969d..7032ff8 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1584,6 +1584,7 @@ zsh_main(UNUSED(int argc), char **argv)
 
     fdtable_size = zopenmax();
     fdtable = zshcalloc(fdtable_size*sizeof(*fdtable));
+    fdtable[0] = fdtable[1] = fdtable[2] = FDT_EXTERNAL;
 
     createoptiontable();
     emulate(zsh_name, 1, &emulation, opts);   /* initialises most options */



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