mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
Use pipe2() instead of pipe() when possible.
This commit is contained in:
parent
2893134940
commit
a80872b314
@ -70,7 +70,7 @@ AC_CHECK_LIB(m, floor)
|
|||||||
AC_CHECK_LIB(socket, getsockname)
|
AC_CHECK_LIB(socket, getsockname)
|
||||||
AC_CHECK_LIB(ws2_32, getsockname)
|
AC_CHECK_LIB(ws2_32, getsockname)
|
||||||
AC_CHECK_LIB(shlwapi, PathRemoveFileSpecA)
|
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_MSG_CHECKING(whether to enable debugging)
|
||||||
AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging (default=no)],, enable_debug=no)
|
AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging (default=no)],, enable_debug=no)
|
||||||
|
@ -69,7 +69,7 @@ Process::Process(const vector<String>& arguments, const Dictionary::Ptr& extraEn
|
|||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
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));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
@ -309,9 +309,23 @@ void Process::InitTask(void)
|
|||||||
#else /* _MSC_VER */
|
#else /* _MSC_VER */
|
||||||
int fds[2];
|
int fds[2];
|
||||||
|
|
||||||
|
#ifdef HAVE_PIPE2
|
||||||
|
if (pipe2(fds, O_NONBLOCK | O_CLOEXEC) < 0)
|
||||||
|
#else /* HAVE_PIPE2 */
|
||||||
if (pipe(fds) < 0)
|
if (pipe(fds) < 0)
|
||||||
|
#endif /* HAVE_PIPE2 */
|
||||||
BOOST_THROW_EXCEPTION(PosixException("pipe() failed.", errno));
|
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
|
#ifdef HAVE_VFORK
|
||||||
m_Pid = vfork();
|
m_Pid = vfork();
|
||||||
#else /* HAVE_VFORK */
|
#else /* HAVE_VFORK */
|
||||||
@ -329,6 +343,7 @@ void Process::InitTask(void)
|
|||||||
_exit(128);
|
_exit(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void) close(fds[0]);
|
||||||
(void) close(fds[1]);
|
(void) close(fds[1]);
|
||||||
|
|
||||||
if (execvpe(m_Arguments[0], m_Arguments, m_Environment) < 0) {
|
if (execvpe(m_Arguments[0], m_Arguments, m_Environment) < 0) {
|
||||||
@ -337,25 +352,25 @@ void Process::InitTask(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_exit(128);
|
_exit(128);
|
||||||
} else {
|
|
||||||
// parent process
|
|
||||||
|
|
||||||
// free arguments
|
|
||||||
for (int i = 0; m_Arguments[i] != NULL; i++)
|
|
||||||
free(m_Arguments[i]);
|
|
||||||
|
|
||||||
delete [] m_Arguments;
|
|
||||||
|
|
||||||
// free environment
|
|
||||||
for (int i = 0; m_Environment[i] != NULL; i++)
|
|
||||||
free(m_Environment[i]);
|
|
||||||
|
|
||||||
delete [] m_Environment;
|
|
||||||
|
|
||||||
(void) close(fds[1]);
|
|
||||||
|
|
||||||
m_FD = fds[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parent process
|
||||||
|
|
||||||
|
// free arguments
|
||||||
|
for (int i = 0; m_Arguments[i] != NULL; i++)
|
||||||
|
free(m_Arguments[i]);
|
||||||
|
|
||||||
|
delete [] m_Arguments;
|
||||||
|
|
||||||
|
// free environment
|
||||||
|
for (int i = 0; m_Environment[i] != NULL; i++)
|
||||||
|
free(m_Environment[i]);
|
||||||
|
|
||||||
|
delete [] m_Environment;
|
||||||
|
|
||||||
|
(void) close(fds[1]);
|
||||||
|
|
||||||
|
m_FD = fds[0];
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user