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 (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 (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);
+ }
+ return -1;
}
- return -1;
+ net_set_nonblock(fd, FALSE);
}
- net_set_nonblock(fd, FALSE);
T_BEGIN {
string_t *str;
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) {
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)
/* 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 {