[dovecot-cvs] dovecot/src/master auth-process.c,1.5,1.6 auth-process.h,1.2,1.3 login-process.c,1.10,1.11 login-process.h,1.2,1.3 main.c,1.12,1.13 settings.c,1.16,1.17 settings.h,1.10,1.11

cras at procontrol.fi cras at procontrol.fi
Wed Nov 20 21:20:25 EET 2002


Update of /home/cvs/dovecot/src/master
In directory danu:/tmp/cvs-serv21649/src/master

Modified Files:
	auth-process.c auth-process.h login-process.c login-process.h 
	main.c settings.c settings.h 
Log Message:
SIGHUP reloads now settings. Logged in clients are left untouched, but
clients still logging in are killed.



Index: auth-process.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/auth-process.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- auth-process.c	28 Oct 2002 04:18:26 -0000	1.5
+++ auth-process.c	20 Nov 2002 19:20:23 -0000	1.6
@@ -297,6 +297,17 @@
 		(void)close(p->fd);
 }
 
+void auth_processes_destroy_all(void)
+{
+	AuthProcess *next;
+
+	while (processes != NULL) {
+		next = processes->next;
+		auth_process_destroy(processes);
+                processes = next;
+	}
+}
+
 static void auth_processes_start_missing(void *context __attr_unused__,
 					 Timeout timeout __attr_unused__)
 {
@@ -319,13 +330,6 @@
 
 void auth_processes_deinit(void)
 {
-	AuthProcess *next;
-
 	timeout_remove(to);
-
-	while (processes != NULL) {
-		next = processes->next;
-		auth_process_destroy(processes);
-                processes = next;
-	}
+	auth_processes_destroy_all();
 }

Index: auth-process.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/auth-process.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- auth-process.h	22 Aug 2002 12:48:38 -0000	1.2
+++ auth-process.h	20 Nov 2002 19:20:23 -0000	1.3
@@ -17,6 +17,7 @@
 
 /* Close any fds used by auth processes */
 void auth_processes_cleanup(void);
+void auth_processes_destroy_all(void);
 
 void auth_processes_init(void);
 void auth_processes_deinit(void);

Index: login-process.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/login-process.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- login-process.c	17 Nov 2002 09:42:08 -0000	1.10
+++ login-process.c	20 Nov 2002 19:20:23 -0000	1.11
@@ -358,6 +358,20 @@
 	hash_foreach(processes, login_hash_cleanup, NULL);
 }
 
+static void login_hash_destroy(void *key __attr_unused__, void *value,
+			       void *context __attr_unused__)
+{
+	login_process_destroy(value);
+}
+
+void login_processes_destroy_all(void)
+{
+	hash_foreach(processes, login_hash_destroy, NULL);
+
+	/* don't double their amount when restarting */
+	wanted_processes_count = 0;
+}
+
 static void login_processes_start_missing(void *context __attr_unused__,
 					  Timeout timeout __attr_unused__)
 {
@@ -400,16 +414,10 @@
 	to = timeout_add(1000, login_processes_start_missing, NULL);
 }
 
-static void login_hash_destroy(void *key __attr_unused__, void *value,
-			       void *context __attr_unused__)
-{
-	login_process_destroy(value);
-}
-
 void login_processes_deinit(void)
 {
 	timeout_remove(to);
 
-	hash_foreach(processes, login_hash_destroy, NULL);
+        login_processes_destroy_all();
 	hash_destroy(processes);
 }

Index: login-process.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/login-process.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- login-process.h	17 Nov 2002 09:42:08 -0000	1.2
+++ login-process.h	20 Nov 2002 19:20:23 -0000	1.3
@@ -3,6 +3,7 @@
 
 void login_process_abormal_exit(pid_t pid);
 void login_processes_cleanup(void);
+void login_processes_destroy_all(void);
 
 void login_processes_init(void);
 void login_processes_deinit(void);

Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/main.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- main.c	17 Nov 2002 09:42:08 -0000	1.12
+++ main.c	20 Nov 2002 19:20:23 -0000	1.13
@@ -25,8 +25,9 @@
 	"ssl-param"
 };
 
+static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf";
 static IOLoop ioloop;
-static Timeout to_children;
+static Timeout to;
 
 HashTable *pids;
 int null_fd, imap_fd, imaps_fd;
@@ -77,13 +78,29 @@
 	io_loop_stop(ioloop);
 }
 
-static void children_check_timeout(void *context __attr_unused__,
-				   Timeout timeout __attr_unused__)
+static void settings_reload(void)
+{
+	i_warning("SIGHUP received - reloading configuration");
+
+	settings_read(configfile);
+
+	/* restart auth and login processes */
+        login_processes_destroy_all();
+        auth_processes_destroy_all();
+}
+
+static void timeout_handler(void *context __attr_unused__,
+			    Timeout timeout __attr_unused__)
 {
 	const char *process_type_name;
 	pid_t pid;
 	int status, process_type;
 
+	if (lib_signal_hup != 0) {
+		settings_reload();
+		lib_signal_hup = 0;
+	}
+
 	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
 		/* get the type and remove from hash */
 		process_type = PID_GET_PROCESS_TYPE(pid);
@@ -148,9 +165,8 @@
 
 	imap_fd = set_imap_port == 0 ? dup(null_fd) :
 		net_listen(imap_ip, &set_imap_port);
-	if (imap_fd == -1) {
+	if (imap_fd == -1)
 		i_fatal("listen(%d) failed: %m", set_imap_port);
-	}
 
 #ifdef HAVE_SSL
 	imaps_fd = set_ssl_cert_file == NULL || *set_ssl_cert_file == '\0' ||
@@ -160,9 +176,8 @@
 #else
 	imaps_fd = dup(null_fd);
 #endif
-	if (imaps_fd == -1) {
+	if (imaps_fd == -1)
 		i_fatal("listen(%d) failed: %m", set_imaps_port);
-	}
 }
 
 static void main_init(void)
@@ -186,7 +201,7 @@
 	}
 
 	pids = hash_create(default_pool, 128, NULL, NULL);
-	to_children = timeout_add(100, children_check_timeout, NULL);
+	to = timeout_add(100, timeout_handler, NULL);
 
 	ssl_init();
 	auth_processes_init();
@@ -202,7 +217,7 @@
 	auth_processes_deinit();
 	ssl_deinit();
 
-	timeout_remove(to_children);
+	timeout_remove(to);
 
 	(void)close(null_fd);
 	(void)close(imap_fd);
@@ -234,7 +249,6 @@
 int main(int argc, char *argv[])
 {
 	/* parse arguments */
-	const char *configfile = SYSCONFDIR "/" PACKAGE ".conf";
 	int foreground = FALSE;
 	int i;
 
@@ -256,6 +270,7 @@
 	}
 
 	/* read and verify settings before forking */
+	settings_init();
 	settings_read(configfile);
 	open_fds();
 

Index: settings.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/settings.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- settings.c	17 Nov 2002 09:42:08 -0000	1.16
+++ settings.c	20 Nov 2002 19:20:23 -0000	1.17
@@ -135,19 +135,6 @@
 	set_login_gid = pw->pw_gid;
 }
 
-static void settings_initialize(void)
-{
-	Setting *set;
-
-	/* strdup() all default settings */
-	for (set = settings; set->name != NULL; set++) {
-		if (set->type == SET_STR) {
-			char **str = set->ptr;
-			*str = i_strdup(*str);
-		}
-	}
-}
-
 static void auth_settings_verify(void)
 {
 	AuthConfig *auth;
@@ -218,6 +205,19 @@
 	return auth;
 }
 
+static void auth_config_free(AuthConfig *auth)
+{
+	i_free(auth->name);
+	i_free(auth->methods);
+	i_free(auth->realms);
+	i_free(auth->userinfo);
+	i_free(auth->userinfo_args);
+	i_free(auth->executable);
+	i_free(auth->user);
+	i_free(auth->chroot);
+	i_free(auth);
+}
+
 static const char *parse_new_auth(const char *name)
 {
 	AuthConfig *auth;
@@ -328,6 +328,16 @@
 	return t_strconcat("Unknown setting: ", key, NULL);
 }
 
+static void settings_free(void)
+{
+	while (auth_processes_config != NULL) {
+		AuthConfig *auth = auth_processes_config;
+
+		auth_processes_config = auth->next;
+                auth_config_free(auth);
+	}
+}
+
 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
 
 void settings_read(const char *path)
@@ -337,7 +347,7 @@
 	char *line, *key, *p;
 	int fd, linenum;
 
-        settings_initialize();
+	settings_free();
 
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
@@ -396,4 +406,17 @@
 	i_buffer_unref(inbuf);
 
         settings_verify();
+}
+
+void settings_init(void)
+{
+	Setting *set;
+
+	/* strdup() all default settings */
+	for (set = settings; set->name != NULL; set++) {
+		if (set->type == SET_STR) {
+			char **str = set->ptr;
+			*str = i_strdup(*str);
+		}
+	}
 }

Index: settings.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/settings.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- settings.h	17 Nov 2002 09:42:08 -0000	1.10
+++ settings.h	20 Nov 2002 19:20:23 -0000	1.11
@@ -69,4 +69,6 @@
 
 void settings_read(const char *path);
 
+void settings_init(void);
+
 #endif




More information about the dovecot-cvs mailing list