From 74af3fcecc6515619ff4f29cec2a781dd11a96e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 7 Oct 2013 11:43:10 +0000 Subject: [PATCH] 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 --- src/unix/utilsunx.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 0900587706..eb377d9f76 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -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