Mercurial > dovecot > original-hg > dovecot-1.2
changeset 635:90a65c017bf0 HEAD
SIGHUP reloads now settings. Logged in clients are left untouched, but
clients still logging in are killed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 20 Nov 2002 21:20:23 +0200 |
parents | 339c176aba1e |
children | 02a80e0f71cb |
files | src/master/auth-process.c src/master/auth-process.h src/master/login-process.c src/master/login-process.h src/master/main.c src/master/settings.c src/master/settings.h |
diffstat | 7 files changed, 93 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/master/auth-process.c Wed Nov 20 20:33:40 2002 +0200 +++ b/src/master/auth-process.c Wed Nov 20 21:20:23 2002 +0200 @@ -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(); }
--- a/src/master/auth-process.h Wed Nov 20 20:33:40 2002 +0200 +++ b/src/master/auth-process.h Wed Nov 20 21:20:23 2002 +0200 @@ -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);
--- a/src/master/login-process.c Wed Nov 20 20:33:40 2002 +0200 +++ b/src/master/login-process.c Wed Nov 20 21:20:23 2002 +0200 @@ -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); }
--- a/src/master/login-process.h Wed Nov 20 20:33:40 2002 +0200 +++ b/src/master/login-process.h Wed Nov 20 21:20:23 2002 +0200 @@ -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);
--- a/src/master/main.c Wed Nov 20 20:33:40 2002 +0200 +++ b/src/master/main.c Wed Nov 20 21:20:23 2002 +0200 @@ -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();
--- a/src/master/settings.c Wed Nov 20 20:33:40 2002 +0200 +++ b/src/master/settings.c Wed Nov 20 21:20:23 2002 +0200 @@ -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) @@ -397,3 +407,16 @@ 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); + } + } +}