]> granicus.if.org Git - icinga2/commitdiff
Fixed incorrect use of F_SETFL.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 13 Feb 2013 11:47:51 +0000 (12:47 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 13 Feb 2013 11:47:51 +0000 (12:47 +0100)
lib/base/application.cpp
lib/base/process-unix.cpp
lib/base/socket.cpp

index 7fdcfa2af7db179c43ab0ae0add56f9378e43d12..9632c2a77b7a66b0a41c5c44c18b72cc31b96577 100644 (file)
@@ -455,17 +455,15 @@ void Application::UpdatePidFile(const String& filename)
        if (m_PidFile == NULL)
                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));
+#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_SETFL, flags | FD_CLOEXEC) < 0)
-                       BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
-#endif /* FD_CLOEXEC */
+       if (fcntl(fileno(m_PidFile), F_SETFD, flags | FD_CLOEXEC) < 0)
+               BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
 
-#ifndef _WIN32
        if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
                ClosePidFile();
 
index 75187fde54f83a862f0e369a9541365dc49abd8c..2c89c4c43a496686b361b3321ad6a9709a286d60 100644 (file)
@@ -36,11 +36,11 @@ void Process::CreateWorkers(void)
        m_TaskFd = fds[1];
 
        int flags;
-       flags = fcntl(fds[1], F_GETFL, 0);
+       flags = fcntl(fds[1], F_GETFD, 0);
        if (flags < 0)
                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));
 
        for (int i = 0; i < thread::hardware_concurrency(); i++) {
@@ -52,11 +52,11 @@ void Process::CreateWorkers(void)
                        BOOST_THROW_EXCEPTION(PosixException("dup() failed.", errno));
 
                int flags;
-               flags = fcntl(childTaskFd, F_GETFL, 0);
+               flags = fcntl(childTaskFd, F_GETFD, 0);
                if (flags < 0)
                        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));
 
                thread t(&Process::WorkerThreadProc, childTaskFd);
@@ -186,18 +186,18 @@ void Process::InitTask(void)
 
 #ifndef HAVE_PIPE2
        int flags;
-       flags = fcntl(fds[0], F_GETFL, 0);
+       flags = fcntl(fds[0], F_GETFD, 0);
        if (flags < 0)
                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));
 
-       flags = fcntl(fds[1], F_GETFL, 0);
+       flags = fcntl(fds[1], F_GETFD, 0);
        if (flags < 0)
                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));
 #endif /* HAVE_PIPE2 */
 
index 8e59b3b80e510e63c91c4a9d6e8015c53227bf51..286548f22f0c31dbad03edc4593f951c0e1d4632 100644 (file)
@@ -68,20 +68,20 @@ void Socket::Start(void)
  */
 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) {
-#ifdef F_GETFL
+#ifndef _WIN32
                int flags;
-               flags = fcntl(fd, F_GETFL, 0);
+               flags = fcntl(fd, F_GETFD, 0);
                if (flags < 0)
                        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));
-#else /* F_GETFL */
+#else /* _WIN32 */
                unsigned long lTrue = 1;
                ioctlsocket(fd, FIONBIO, &lTrue);
-#endif /* F_GETFL */
+#endif /* _WIN32 */
        }
 
        m_FD = fd;