[icinga-checkins] icinga.org: icinga2/master: Fixed incorrect use of F_SETFL.

git at icinga.org git at icinga.org
Wed Feb 13 12:47:59 CET 2013


Module: icinga2
Branch: master
Commit: fac2304ae555fa6c880da35effdda39b2c16a611
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=fac2304ae555fa6c880da35effdda39b2c16a611

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Feb 13 12:47:51 2013 +0100

Fixed incorrect use of F_SETFL.

---

 lib/base/application.cpp  |   16 +++++++---------
 lib/base/process-unix.cpp |   16 ++++++++--------
 lib/base/socket.cpp       |   12 ++++++------
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index 7fdcfa2..9632c2a 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -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();
 
diff --git a/lib/base/process-unix.cpp b/lib/base/process-unix.cpp
index 75187fd..2c89c4c 100644
--- a/lib/base/process-unix.cpp
+++ b/lib/base/process-unix.cpp
@@ -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 */
 
diff --git a/lib/base/socket.cpp b/lib/base/socket.cpp
index 8e59b3b..286548f 100644
--- a/lib/base/socket.cpp
+++ b/lib/base/socket.cpp
@@ -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;





More information about the icinga-checkins mailing list