Bugfix: Don't leak lock file's fd into child processes.

This commit is contained in:
Gunnar Beutner 2013-02-08 10:23:01 +01:00
parent 601c7d25d1
commit 513b3d6820
1 changed files with 10 additions and 1 deletions

View File

@ -458,6 +458,16 @@ 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(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 #ifndef _WIN32
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) { if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
ClosePidFile(); ClosePidFile();
@ -576,4 +586,3 @@ void Application::SetPkgDataDir(const String& path)
{ {
m_PkgDataDir = path; m_PkgDataDir = path;
} }