mirror of https://github.com/Icinga/icinga2.git
Fixed incorrect use of F_SETFL.
This commit is contained in:
parent
4f2021633b
commit
fac2304ae5
|
@ -455,17 +455,15 @@ void Application::UpdatePidFile(const String& filename)
|
||||||
if (m_PidFile == NULL)
|
if (m_PidFile == NULL)
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'"));
|
BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'"));
|
||||||
|
|
||||||
#ifdef F_GETFL
|
|
||||||
int flags;
|
|
||||||
flags = fcntl(fileno(m_PidFile), F_GETFL, 0);
|
|
||||||
if (flags < 0)
|
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
|
||||||
|
|
||||||
if (fcntl(fileno(m_PidFile), F_SETFL, flags | FD_CLOEXEC) < 0)
|
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
|
||||||
#endif /* FD_CLOEXEC */
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
int flags;
|
||||||
|
flags = fcntl(fileno(m_PidFile), F_GETFD, 0);
|
||||||
|
if (flags < 0)
|
||||||
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
|
if (fcntl(fileno(m_PidFile), F_SETFD, flags | FD_CLOEXEC) < 0)
|
||||||
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
|
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
|
||||||
ClosePidFile();
|
ClosePidFile();
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,11 @@ void Process::CreateWorkers(void)
|
||||||
m_TaskFd = fds[1];
|
m_TaskFd = fds[1];
|
||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
flags = fcntl(fds[1], F_GETFL, 0);
|
flags = fcntl(fds[1], F_GETFD, 0);
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
if (fcntl(fds[1], F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
if (fcntl(fds[1], F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
for (int i = 0; i < thread::hardware_concurrency(); i++) {
|
for (int i = 0; i < thread::hardware_concurrency(); i++) {
|
||||||
|
@ -52,11 +52,11 @@ void Process::CreateWorkers(void)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("dup() failed.", errno));
|
BOOST_THROW_EXCEPTION(PosixException("dup() failed.", errno));
|
||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
flags = fcntl(childTaskFd, F_GETFL, 0);
|
flags = fcntl(childTaskFd, F_GETFD, 0);
|
||||||
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 | FD_CLOEXEC) < 0)
|
if (fcntl(childTaskFd, F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
thread t(&Process::WorkerThreadProc, childTaskFd);
|
thread t(&Process::WorkerThreadProc, childTaskFd);
|
||||||
|
@ -186,18 +186,18 @@ void Process::InitTask(void)
|
||||||
|
|
||||||
#ifndef HAVE_PIPE2
|
#ifndef HAVE_PIPE2
|
||||||
int flags;
|
int flags;
|
||||||
flags = fcntl(fds[0], F_GETFL, 0);
|
flags = fcntl(fds[0], F_GETFD, 0);
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
if (fcntl(fds[0], F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
if (fcntl(fds[0], F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
flags = fcntl(fds[1], F_GETFL, 0);
|
flags = fcntl(fds[1], F_GETFD, 0);
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
if (fcntl(fds[1], F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
if (fcntl(fds[1], F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
#endif /* HAVE_PIPE2 */
|
#endif /* HAVE_PIPE2 */
|
||||||
|
|
||||||
|
|
|
@ -68,20 +68,20 @@ void Socket::Start(void)
|
||||||
*/
|
*/
|
||||||
void Socket::SetFD(SOCKET fd)
|
void Socket::SetFD(SOCKET fd)
|
||||||
{
|
{
|
||||||
/* mark the socket as non-blocking */
|
/* mark the socket as non-blocking and close-on-exec */
|
||||||
if (fd != INVALID_SOCKET) {
|
if (fd != INVALID_SOCKET) {
|
||||||
#ifdef F_GETFL
|
#ifndef _WIN32
|
||||||
int flags;
|
int flags;
|
||||||
flags = fcntl(fd, F_GETFL, 0);
|
flags = fcntl(fd, F_GETFD, 0);
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0)
|
if (fcntl(fd, F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
|
||||||
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
|
||||||
#else /* F_GETFL */
|
#else /* _WIN32 */
|
||||||
unsigned long lTrue = 1;
|
unsigned long lTrue = 1;
|
||||||
ioctlsocket(fd, FIONBIO, &lTrue);
|
ioctlsocket(fd, FIONBIO, &lTrue);
|
||||||
#endif /* F_GETFL */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
m_FD = fd;
|
m_FD = fd;
|
||||||
|
|
Loading…
Reference in New Issue