From 63c95fd17de0aa6165153a443747598a5f9a08af Mon Sep 17 00:00:00 2001 From: Marji Cermak Date: Wed, 14 Jan 2015 16:38:30 +1100 Subject: [PATCH] refs #52: try to remove stale pid file instead of aborting. --- src/daemon.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/daemon.c b/src/daemon.c index 07e3271..d8ad669 100755 --- a/src/daemon.c +++ b/src/daemon.c @@ -55,6 +55,12 @@ int read_pid() if(file != NULL) { fscanf(file, "%d", &pid); fclose(file); + if (kill(pid, 0) == -1 && errno == ESRCH) + { /* a process with such a pid does not exist, remove the pid file */ + if (remove(PROGRAM_PID) == 0) { + return -1; + } + } return pid; }