charon: Ignore an existing PID file if it references ourself

If a daemon PID file references the process that does the check, it is safe
to ignore it; no running process can have the same PID. While this is rather
unlikely to get restarted with the same PID under normal conditions, it is
quite common when running inside PID namespaced containers: If a container
gets stopped and restarted with a PID file remaining, it is very likely that
the PID namespace assigns the same PID to our service, as they are assigned
sequentially starting from 1.
This commit is contained in:
Martin Willi 2018-03-12 07:16:52 +01:00 committed by Tobias Brunner
parent a7005e435b
commit 9655a3ffbc
1 changed files with 1 additions and 1 deletions

View File

@ -204,7 +204,7 @@ static bool check_pidfile()
}
fclose(pidfile);
pidfile = NULL;
if (pid && kill(pid, 0) == 0)
if (pid && pid != getpid() && kill(pid, 0) == 0)
{
DBG1(DBG_DMN, "charon already running ('"PID_FILE"' exists)");
return TRUE;