[Mono-dev] Process.Start closing file descriptors

Weeble clockworksaint at gmail.com
Fri Jan 27 11:54:56 UTC 2012


I have a program that uses
System.IO.Pipes.AnonymousPipe{Server,Client}Stream on .NET to
communicate between a parent and child process while still allowing
the child process to use stdin, stdout and stderr normally. I've found
that this part of System.IO.Pipes isn't implemented in Mono. From what
I can tell, it shouldn't be especially hard to implement these classes
themselves, but the critical problem would be that Process.Start
explicitly closes all open file descriptors (except for stdin, stdout
and stderr). The relevant code is here, in CreateProcess in
processes.c:

https://github.com/mono/mono/blob/master/mono/io-layer/processes.c#L988

Because of that, I believe any working implementation of
System.IO.Pipes.Anonymous* would require changes to CreateProcess.
Either:

1. Remove entirely the loop that closes file descriptors.

or

2. Maintain a process-wide table of all file descriptors associated
with the client-end of an AnonymousPipeServerStream, pass it into
CreateProcess and skip closing of those file descriptors.

Could anyone comment whether there's a good reason not to do 1? Is
this compensating for a mismatch between Windows and non-Windows file
handle/descriptor behaviour?

If there is indeed a good reason not to do that, is 2 feasible? Are
there any traps to watch out for here? Perhaps if there are multiple
AppDomains?

Regards,
Weeble.


More information about the Mono-devel-list mailing list