dbus-sysdeps-unix.h

Tor Lillqvist tml at iki.fi
Fri Sep 15 03:00:20 PDT 2006


Thiago Macieira writes:
 > No streams survive in the child process on Windows except stdin, stdout 
 > and stderr (IIRC).

This is incorrect. File HANDLEs and SOCKETs are inherited by child
processes, unless specifically set to be noninherited.

The mapping from C file descriptors to HANDLEs is also inherited
through user-level magic code in the C library exec()/spawn() and crt0
code, but obviously this is relevant only if both parent and child use
the C library (well, any one of the Microsoft ones), which not
necessarily always is the case.

Unfortunately it seems to be impossible to turn the HANDLEs (and the C
file descriptor to HANDLE mapping) for random file descriptors passed
into your code into noninherited. You can use DuplicateHandle() to
create a noninherited duplicate HANDLE of the underlying fd. You can
then create a new fd mapping of that HANDLE with
_open_osfhandle(). But if you then try to use dup2() from the new fd
to the old one, dup2() will also itself call DuplicateHandle(), but
passing TRUE for the bInheritHandle parameter ;)

The above is a problem if the API is such that the file descriptors
are created beyond the code in question's control; code that opens the
files itself from scratch can use all the necessary magic to get
noninherited HANDLEs and fds.

--tml



More information about the dbus mailing list