From bef68aec3ac6ac399d9c19bf455ad42fb2a8a9a1 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Thu, 11 Jan 2018 10:56:32 +0100 Subject: [PATCH] added pidfile check in piler.c to prevent multiple start of the piler daemon Signed-off-by: Janos SUTO --- src/config.h | 2 +- src/errmsg.h | 1 + src/piler.c | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index 4b80e0c8..f910107a 100644 --- a/src/config.h +++ b/src/config.h @@ -11,7 +11,7 @@ #define VERSION "1.3.2" -#define BUILD 983 +#define BUILD 985 #define HOSTID "mailarchiver" diff --git a/src/errmsg.h b/src/errmsg.h index 860f6676..cb9df8b3 100644 --- a/src/errmsg.h +++ b/src/errmsg.h @@ -20,6 +20,7 @@ #define ERR_TIMED_OUT "ERR: timed out" #define ERR_FORK_FAILED "ERR: cannot fork()" #define ERR_OPEN_DEDUP_FILE "ERR: cannot open dedup file" +#define ERR_PID_FILE_EXISTS "ERR: pidfile exists. If piler daemon is not running, and the pidfile exists (unclean shutdown?) then remove it, and start piler again" #define ERR_MYSQL_CONNECT "Cannot connect to mysql server" #define ERR_PSQL_CONNECT "Cannot connect to PSql server" diff --git a/src/piler.c b/src/piler.c index 617c6053..534403a3 100644 --- a/src/piler.c +++ b/src/piler.c @@ -461,6 +461,7 @@ void initialise_configuration(){ int main(int argc, char **argv){ int i, daemonise=0, dedupfd; + struct stat st; while((i = getopt(argc, argv, "c:dvVh")) > 0){ @@ -509,6 +510,8 @@ int main(int argc, char **argv){ if(drop_privileges(pwd)) fatal(ERR_SETUID); + if(stat(cfg.pidfile, &st) == 0) fatal(ERR_PID_FILE_EXISTS); + if(cfg.mmap_dedup_test == 1){ dedupfd = open(MESSAGE_ID_DEDUP_FILE, O_RDWR); if(dedupfd == -1) fatal(ERR_OPEN_DEDUP_FILE);