[icinga-checkins] icinga.org: icinga2/master: Fix writing the PID file if there is no previous PID file.

git at icinga.org git at icinga.org
Tue Mar 12 16:03:56 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Mar 12 16:02:35 2013 +0100

Fix writing the PID file if there is no previous PID file.

---

 lib/base/application.cpp |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index 8c9c8b4..c21be8e 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -462,15 +462,12 @@ void Application::UpdatePidFile(const String& filename)
 	if (m_PidFile != NULL)
 		fclose(m_PidFile);
 
-#ifndef _WIN32
-	const char *mode = "r+";
-#else /* _WIN32 */
-	const char *mode = "w";
-#endif /* _WIN32 */
-
 	/* There's just no sane way of getting a file descriptor for a
 	 * C++ ofstream which is why we're using FILEs here. */
-	m_PidFile = fopen(filename.CStr(), mode);
+	m_PidFile = fopen(filename.CStr(), "r+");
+
+	if (m_PidFile == NULL)
+		m_PidFile = fopen(filename.CStr(), "w");
 
 	if (m_PidFile == NULL)
 		BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'"));





More information about the icinga-checkins mailing list