diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 0b9f4d0ca..b4bd319da 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -435,7 +435,7 @@ int Main(void) if (!g_AppParams.count("validate") && !g_AppParams.count("reload-internal")) { pid_t runningpid = Application::ReadPidFile(Application::GetPidPath()); - if (runningpid >= 0) { + if (runningpid > 0) { Log(LogCritical, "icinga-app", "Another instance of Icinga already running with PID " + Convert::ToString(runningpid)); return EXIT_FAILURE; } diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 8c7ca7652..03a3cf64b 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -682,14 +682,14 @@ void Application::ClosePidFile(void) * Checks if another process currently owns the pidfile and read it * * @param filename The name of the PID file. - * @returns -1: no process owning the pidfile, pid of the process otherwise + * @returns 0: no process owning the pidfile, pid of the process otherwise */ pid_t Application::ReadPidFile(const String& filename) { FILE *pidfile = fopen(filename.CStr(), "r"); if (pidfile == NULL) - return -1; + return 0; #ifndef _WIN32 int fd = fileno(pidfile); @@ -722,10 +722,15 @@ pid_t Application::ReadPidFile(const String& filename) // bogus result? if (res != 1) - return -1; + return 0; #ifdef _WIN32 - // TODO: add check if the read pid is still running or not + HANDLE hProcess = OpenProcess(0, FALSE, runningpid); + + if (!hProcess) + return 0; + + CloseHandle(hProcess); #endif /* _WIN32 */ return runningpid;