Mercurial > dovecot > core-2.2
changeset 9282:6bb773332683 HEAD
lib-master: Added support for keeping config connection open and reusing it for later requests.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 14 May 2009 18:52:54 -0400 |
parents | 11e974e40f7b |
children | 02721ba17309 |
files | src/lib-master/master-service-private.h src/lib-master/master-service-settings.c src/lib-master/master-service.c src/lib-master/master-service.h |
diffstat | 4 files changed, 29 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-master/master-service-private.h Thu May 14 18:52:01 2009 -0400 +++ b/src/lib-master/master-service-private.h Thu May 14 18:52:54 2009 -0400 @@ -22,8 +22,9 @@ const char *version_string; const char *config_path; + ARRAY_TYPE(const_string) config_overrides; + int config_fd; int syslog_facility; - ARRAY_TYPE(const_string) config_overrides; unsigned int socket_count, ssl_socket_count; struct master_service_listener *listeners;
--- a/src/lib-master/master-service-settings.c Thu May 14 18:52:01 2009 -0400 +++ b/src/lib-master/master-service-settings.c Thu May 14 18:52:54 2009 -0400 @@ -106,19 +106,24 @@ int fd, ret; path = master_service_get_config_path(service); - fd = net_connect_unix(path); - if (fd < 0) { - *error_r = t_strdup_printf("net_connect_unix(%s) failed: %m", - path); + if (service->config_fd != -1) { + fd = service->config_fd; + service->config_fd = -1; + } else { + fd = net_connect_unix(path); + if (fd < 0) { + *error_r = t_strdup_printf( + "net_connect_unix(%s) failed: %m", path); - if (stat(path, &st) == 0 && !S_ISFIFO(st.st_mode)) { - /* it's a file, not a socket */ - master_service_exec_config(service, - input->preserve_home); + if (stat(path, &st) == 0 && !S_ISFIFO(st.st_mode)) { + /* it's a file, not a socket */ + master_service_exec_config(service, + input->preserve_home); + } + return -1; } - return -1; + net_set_nonblock(fd, FALSE); } - net_set_nonblock(fd, FALSE); T_BEGIN { string_t *str; @@ -221,9 +226,16 @@ i_assert(ret <= 0); if (ret < 0) { *error_r = settings_parser_get_error(parser); + (void)close(fd); return -1; } } + + if ((service->flags & MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN) == 0) + (void)close(fd); + else + service->config_fd = fd; + /* let environment override settings. especially useful for the settings from userdb. */ if (settings_parse_environ(parser) < 0) {
--- a/src/lib-master/master-service.c Thu May 14 18:52:01 2009 -0400 +++ b/src/lib-master/master-service.c Thu May 14 18:52:54 2009 -0400 @@ -96,6 +96,7 @@ service->flags = flags; service->ioloop = io_loop_create(); service->service_count_left = (unsigned int)-1; + service->config_fd = -1; service->config_path = getenv(MASTER_CONFIG_FILE_ENV); if (service->config_path == NULL)
--- a/src/lib-master/master-service.h Thu May 14 18:52:01 2009 -0400 +++ b/src/lib-master/master-service.h Thu May 14 18:52:54 2009 -0400 @@ -9,7 +9,10 @@ /* this process is currently running standalone without a master */ MASTER_SERVICE_FLAG_STANDALONE = 0x02, /* Log to stderr instead of the configured log file */ - MASTER_SERVICE_FLAG_LOG_TO_STDERR = 0x04 + MASTER_SERVICE_FLAG_LOG_TO_STDERR = 0x04, + /* Service is going to do multiple configuration lookups, + keep the connection to config service open. */ + MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN = 0x08 }; struct master_service_connection {