AC_CHECK_LIB(socket, getsockname)
AC_CHECK_LIB(ws2_32, getsockname)
AC_CHECK_LIB(shlwapi, PathRemoveFileSpecA)
-AC_CHECK_FUNCS([backtrace_symbols execvpe])
+AC_CHECK_FUNCS([backtrace_symbols execvpe pipe2])
AC_MSG_CHECKING(whether to enable debugging)
AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging (default=no)],, enable_debug=no)
if (flags < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(childTaskFd, F_SETFL, flags | O_NONBLOCK) < 0)
+ if (fcntl(childTaskFd, F_SETFL, flags | O_NONBLOCK | O_CLOEXEC) < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
#endif /* _MSC_VER */
#else /* _MSC_VER */
int fds[2];
+#ifdef HAVE_PIPE2
+ if (pipe2(fds, O_NONBLOCK | O_CLOEXEC) < 0)
+#else /* HAVE_PIPE2 */
if (pipe(fds) < 0)
+#endif /* HAVE_PIPE2 */
BOOST_THROW_EXCEPTION(PosixException("pipe() failed.", errno));
+#ifndef HAVE_PIPE2
+ int flags;
+ flags = fcntl(childTaskFd, F_GETFL, 0);
+ if (flags < 0)
+ BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
+
+ if (fcntl(childTaskFd, F_SETFL, flags | O_NONBLOCK | O_CLOEXEC) < 0)
+ BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
+#endif /* HAVE_PIPE2 */
+
#ifdef HAVE_VFORK
m_Pid = vfork();
#else /* HAVE_VFORK */
_exit(128);
}
+ (void) close(fds[0]);
(void) close(fds[1]);
if (execvpe(m_Arguments[0], m_Arguments, m_Environment) < 0) {
}
_exit(128);
- } else {
- // parent process
+ }
- // free arguments
- for (int i = 0; m_Arguments[i] != NULL; i++)
- free(m_Arguments[i]);
+ // parent process
- delete [] m_Arguments;
+ // free arguments
+ for (int i = 0; m_Arguments[i] != NULL; i++)
+ free(m_Arguments[i]);
- // free environment
- for (int i = 0; m_Environment[i] != NULL; i++)
- free(m_Environment[i]);
+ delete [] m_Arguments;
- delete [] m_Environment;
+ // free environment
+ for (int i = 0; m_Environment[i] != NULL; i++)
+ free(m_Environment[i]);
- (void) close(fds[1]);
+ delete [] m_Environment;
- m_FD = fds[0];
- }
+ (void) close(fds[1]);
+
+ m_FD = fds[0];
#endif /* _MSC_VER */
}