]> granicus.if.org Git - icinga2/commitdiff
Added Utility::GetPid() helper function.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 19 Sep 2012 11:00:48 +0000 (13:00 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 19 Sep 2012 11:00:48 +0000 (13:00 +0200)
lib/base/application.cpp
lib/base/utility.cpp
lib/base/utility.h
lib/base/win32.h

index 66a337b1743da56822482f91c35b2c4c36dd911d..fc36f4605ffbb7b514ac50f7ee074de652b097c9 100644 (file)
@@ -347,13 +347,7 @@ void Application::UpdatePidFile(const String& filename)
        }
 #endif /* _WIN32 */
 
-#ifndef _WIN32
-       pid_t pid = getpid();
-#else /* _WIN32 */
-       DWORD pid = GetCurrentProcessId();
-#endif /* _WIN32 */
-
-       fprintf(m_PidFile, "%d", pid);
+       fprintf(m_PidFile, "%d", Utility::GetPid());
        fflush(m_PidFile);
 }
 
index b64e6b14506aed7759d649f956a52945f50df2e5..a34512e4d88b29bd94ed2326595c4dcdfda604f6 100644 (file)
@@ -289,3 +289,17 @@ double Utility::GetTime(void)
        return tv.tv_sec + tv.tv_usec / 1000000.0;
 #endif /* _WIN32 */
 }
+
+/**
+ * Returns the ID of the current process.
+ *
+ * @returns The PID.
+ */
+pid_t Utility::GetPid(void)
+{
+#ifndef _WIN32
+       return getpid();
+#else /* _WIN32 */
+       return GetCurrentProcessId();
+#endif /* _WIN32 */
+}
index 7ff9a2ab21c50a6524993f2df848f0a7ff909236..96c914a377adb7a7f3b527f9580ea23750e9d03d 100644 (file)
@@ -48,6 +48,8 @@ public:
 
        static double GetTime(void);
 
+       static pid_t GetPid(void);
+
 private:
        static bool m_SSLInitialized;
 
index fea3d795db39381b21911a467105a86a9e296688..a6fc28d9cfe8824c5288fb24836c5ed5f0e07f0f 100644 (file)
@@ -35,6 +35,7 @@
 #endif /* __MINGW32__ */
 
 typedef int socklen_t;
+typedef DWORD pid_t;
 
 #define MAXPATHLEN MAX_PATH