[dovecot-cvs] dovecot/src/master main.c,1.65,1.66

cras at dovecot.org cras at dovecot.org
Sun Sep 25 14:07:42 EEST 2005


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv8918/master

Modified Files:
	main.c 
Log Message:
Implemented new signal handling framework, which makes handling signals much
easier.



Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/main.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- main.c	18 Sep 2005 17:18:18 -0000	1.65
+++ main.c	25 Sep 2005 11:07:40 -0000	1.66
@@ -34,8 +34,6 @@
 
 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf";
 static struct timeout *to;
-static unsigned int settings_reload_hup_count = 0;
-static unsigned int log_reopen_usr1_count = 0;
 static const char *env_tz;
 
 struct ioloop *ioloop;
@@ -95,11 +93,6 @@
 	execv(executable, (char **)argv);
 }
 
-static void sig_quit(int signo __attr_unused__)
-{
-	io_loop_stop(ioloop);
-}
-
 static void set_logfile(struct settings *set)
 {
 	if (set->log_path == NULL)
@@ -134,6 +127,27 @@
 	}
 }
 
+static void sig_die(int signo, void *context __attr_unused__)
+{
+	/* warn about being killed because of some signal, except SIGINT (^C)
+	   which is too common at least while testing :) */
+	if (signo != SIGINT)
+		i_warning("Killed with signal %d", signo);
+	io_loop_stop(ioloop);
+}
+
+static void sig_reload_settings(int signo __attr_unused__,
+				void *context __attr_unused__)
+{
+	settings_reload();
+}
+
+static void sig_reopen_logs(int signo __attr_unused__,
+			    void *context __attr_unused__)
+{
+	set_logfile(settings_root->defaults);
+}
+
 static const char *get_exit_status_message(enum fatal_exit_status status)
 {
 	switch (status) {
@@ -161,15 +175,6 @@
 	pid_t pid;
 	int status, process_type;
 
-	if (lib_signal_hup_count != settings_reload_hup_count) {
-		settings_reload_hup_count = lib_signal_hup_count;
-		settings_reload();
-	}
-	if (lib_signal_usr1_count != log_reopen_usr1_count) {
-		log_reopen_usr1_count = lib_signal_usr1_count;
-                set_logfile(settings_root->defaults);
-	}
-
 	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
 		/* get the type and remove from hash */
 		process_type = PID_GET_PROCESS_TYPE(pid);
@@ -511,7 +516,12 @@
 
 	log_init();
 
-	lib_init_signals(sig_quit);
+	lib_signals_init();
+        lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
+        lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
+        lib_signals_set_handler(SIGPIPE, FALSE, NULL, NULL);
+        lib_signals_set_handler(SIGHUP, TRUE, sig_reload_settings, NULL);
+        lib_signals_set_handler(SIGUSR1, TRUE, sig_reopen_logs, NULL);
 
 	pids = hash_create(default_pool, default_pool, 128, NULL, NULL);
 	to = timeout_add(100, timeout_handler, NULL);
@@ -526,9 +536,6 @@
 
 static void main_deinit(void)
 {
-        if (lib_signal_kill != 0)
-		i_warning("Killed with signal %d", lib_signal_kill);
-
 	(void)unlink(t_strconcat(settings_root->defaults->base_dir,
 				 "/master.pid", NULL));
 
@@ -545,6 +552,7 @@
 		i_error("close(null_fd) failed: %m");
 
 	hash_destroy(pids);
+	lib_signals_deinit();
 	log_deinit();
 	closelog();
 }



More information about the dovecot-cvs mailing list