From d609264a006a2fce77a9991aa55bb152d3418a2a Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Tue, 6 Dec 2016 16:39:04 -0600 Subject: [PATCH] Only rm pidfile if PID matches --- lib/roken/write_pid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/roken/write_pid.c b/lib/roken/write_pid.c index 4ebdcae45..308e17696 100644 --- a/lib/roken/write_pid.c +++ b/lib/roken/write_pid.c @@ -77,11 +77,12 @@ pid_file_delete(char **filename) } static char *pidfile_path; +static pid_t pidfile_pid; static void pidfile_cleanup(void) { - if (pidfile_path != NULL) + if (pidfile_path != NULL && pidfile_pid == getpid()) pid_file_delete(&pidfile_path); } @@ -103,6 +104,7 @@ pidfile(const char *bname) if (bname == NULL) bname = getprogname(); pidfile_path = pid_file_write(bname); + pidfile_pid = getpid(); #if defined(HAVE_ATEXIT) if (pidfile_path != NULL) atexit(pidfile_cleanup);