mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 15:14:07 +02:00
parent
5e094ed185
commit
630a1a28e2
@ -435,7 +435,7 @@ int Main(void)
|
|||||||
|
|
||||||
if (!g_AppParams.count("validate") && !g_AppParams.count("reload-internal")) {
|
if (!g_AppParams.count("validate") && !g_AppParams.count("reload-internal")) {
|
||||||
pid_t runningpid = Application::ReadPidFile(Application::GetPidPath());
|
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));
|
Log(LogCritical, "icinga-app", "Another instance of Icinga already running with PID " + Convert::ToString(runningpid));
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -682,14 +682,14 @@ void Application::ClosePidFile(void)
|
|||||||
* Checks if another process currently owns the pidfile and read it
|
* Checks if another process currently owns the pidfile and read it
|
||||||
*
|
*
|
||||||
* @param filename The name of the PID file.
|
* @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)
|
pid_t Application::ReadPidFile(const String& filename)
|
||||||
{
|
{
|
||||||
FILE *pidfile = fopen(filename.CStr(), "r");
|
FILE *pidfile = fopen(filename.CStr(), "r");
|
||||||
|
|
||||||
if (pidfile == NULL)
|
if (pidfile == NULL)
|
||||||
return -1;
|
return 0;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
int fd = fileno(pidfile);
|
int fd = fileno(pidfile);
|
||||||
@ -722,10 +722,15 @@ pid_t Application::ReadPidFile(const String& filename)
|
|||||||
|
|
||||||
// bogus result?
|
// bogus result?
|
||||||
if (res != 1)
|
if (res != 1)
|
||||||
return -1;
|
return 0;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#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 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
return runningpid;
|
return runningpid;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user