Workaround OS X crash when closing FDs in wxExecute.

wxExecute() closes all file descriptors in the forked child process.
This is a common practice, but it unfortunately breaks in combination
with libdispatch on OS X, which - instead of gracefully handling the
situation - intentionally(!) crashes when something closes its kevent
file descriptor in OS X 10.8.

There's doesn't seem to be a simple way to get this descriptor and
there's no telling when libdispatch is pulled into the executable, so
just leave the file descriptors be when running under Darwin, until a
better fix is found.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74957 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2013-10-07 11:43:10 +00:00
parent d92a17f52d
commit 74af3fcecc

View File

@ -697,6 +697,7 @@ long wxExecute(char **argv, int flags, wxProcess *process,
// the descriptors do not need to be closed but for now this is better
// than never closing them at all as wx code never used FD_CLOEXEC.
#ifdef __DARWIN__
// TODO: Iterating up to FD_SETSIZE is both inefficient (because it may
// be quite big) and incorrect (because in principle we could
// have more opened descriptions than this number). Unfortunately
@ -704,6 +705,14 @@ long wxExecute(char **argv, int flags, wxProcess *process,
// above a certain threshold but non-portable solutions exist for
// most platforms, see [http://stackoverflow.com/questions/899038/
// getting-the-highest-allocated-file-descriptor]
//
// Unfortunately, we cannot do this safely on OS X, because libdispatch
// may crash when we do this:
// Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
// Exception Codes: 0x0000000000000001, 0x0000000000000000
//
// Application Specific Information:
// BUG IN CLIENT OF LIBDISPATCH: Do not close random Unix descriptors
for ( int fd = 0; fd < (int)FD_SETSIZE; ++fd )
{
if ( fd != STDIN_FILENO &&
@ -713,6 +722,7 @@ long wxExecute(char **argv, int flags, wxProcess *process,
close(fd);
}
}
#endif // !__DARWIN__
// Process additional options if we have any