changeset 7165:805d0831deb6 HEAD

If we see that Dovecot is already running, log the error as fatal instead of later giving "Invalid configuration" fatal.
author Timo Sirainen <tss@iki.fi>
date Wed, 16 Jan 2008 18:41:02 +0200
parents d349cdeddc7d
children c8f5955a4cf8
files src/master/master-settings.c
diffstat 1 files changed, 6 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/master/master-settings.c	Wed Jan 16 18:24:09 2008 +0200
+++ b/src/master/master-settings.c	Wed Jan 16 18:41:02 2008 +0200
@@ -906,7 +906,7 @@
 	return nofixes ? TRUE : settings_do_fixes(set);
 }
 
-static int pid_file_is_running(const char *path)
+static void pid_file_check_running(const char *path)
 {
 	char buf[32];
 	int fd;
@@ -915,9 +915,8 @@
 	fd = open(path, O_RDONLY);
 	if (fd == -1) {
 		if (errno == ENOENT)
-			return 0;
-		i_error("open(%s) failed: %m", path);
-		return -1;
+			return;
+		i_fatal("open(%s) failed: %m", path);
 	}
 
 	ret = read(fd, buf, sizeof(buf));
@@ -925,7 +924,7 @@
 		if (ret == 0)
 			i_error("Empty PID file in %s, overriding", path);
 		else
-			i_error("read(%s) failed: %m", path);
+			i_fatal("read(%s) failed: %m", path);
 	} else {
 		pid_t pid;
 
@@ -935,15 +934,12 @@
 		pid = atoi(buf);
 		if (pid == getpid() || (kill(pid, 0) < 0 && errno == ESRCH)) {
 			/* doesn't exist */
-			ret = 0;
 		} else {
-			i_error("Dovecot is already running with PID %s "
+			i_fatal("Dovecot is already running with PID %s "
 				"(read from %s)", buf, path);
-			ret = 1;
 		}
 	}
 	(void)close(fd);
-	return ret;
 }
 
 static struct auth_settings *
@@ -1458,8 +1454,7 @@
 
 		path = t_strconcat(ctx.root->defaults->base_dir,
 				   "/master.pid", NULL);
-		if (pid_file_is_running(path) != 0)
-			return FALSE;
+		pid_file_check_running(path);
 	}
 
 	prev = NULL;