From 9655a3ffbc53d13e6f9ef96823fd823c3083cec4 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Mon, 12 Mar 2018 07:16:52 +0100 Subject: [PATCH] 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. --- src/charon/charon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/charon/charon.c b/src/charon/charon.c index f23717034..1d1e623c1 100644 --- a/src/charon/charon.c +++ b/src/charon/charon.c @@ -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;