]> granicus.if.org Git - icinga2/commitdiff
Bugfix: Don't leak lock file's fd into child processes.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 8 Feb 2013 09:23:01 +0000 (10:23 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 8 Feb 2013 09:23:01 +0000 (10:23 +0100)
lib/base/application.cpp

index dcc4e5a7009f7c4bae0e0c59f08956f6888205cc..e34f2fcb503cbbd8bb8ab185ef4eed71b1b35926 100644 (file)
@@ -458,6 +458,16 @@ 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(fd, F_GETFL, 0);
+               if (flags < 0)
+                       BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
+
+               if (fcntl(fd, F_SETFL, flags | FD_CLOEXEC) < 0)
+                       BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
+#endif /* FD_CLOEXEC */
+
 #ifndef _WIN32
        if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
                ClosePidFile();
@@ -576,4 +586,3 @@ void Application::SetPkgDataDir(const String& path)
 {
         m_PkgDataDir = path;
 }
-