From: Timo Sirainen Date: Thu, 10 Oct 2013 17:50:10 +0000 (+0300) Subject: master: host.domain lookups weren't cached, they were done at the worst possible... X-Git-Tag: 2.2.7~90 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28482afc8139462ff9bcc6cedc4936129e8763ef;p=thirdparty%2Fdovecot%2Fcore.git master: host.domain lookups weren't cached, they were done at the worst possible time. This fixes "net_connect_unix(imap) failed: Resource temporarily unavailable" and various other issues where processes weren't being created fast enough if the host.domain lookup was slow (e.g. done via external DNS). --- diff --git a/src/master/service-process.c b/src/master/service-process.c index c3a5b87b64..73dd521cf5 100644 --- a/src/master/service-process.c +++ b/src/master/service-process.c @@ -237,7 +237,8 @@ static void service_process_setup_config_environment(struct service *service) } static void -service_process_setup_environment(struct service *service, unsigned int uid) +service_process_setup_environment(struct service *service, unsigned int uid, + const char *hostdomain) { master_service_env_clean(); @@ -257,7 +258,7 @@ service_process_setup_environment(struct service *service, unsigned int uid) } env_put(t_strdup_printf(MASTER_UID_ENV"=%u", uid)); env_put(t_strdup_printf(MY_HOSTNAME_ENV"=%s", my_hostname)); - env_put(t_strdup_printf(MY_HOSTDOMAIN_ENV"=%s", my_hostdomain())); + env_put(t_strdup_printf(MY_HOSTDOMAIN_ENV"=%s", hostdomain)); if (!service->set->master_set->version_ignore) env_put(MASTER_DOVECOT_VERSION_ENV"="PACKAGE_VERSION); @@ -291,6 +292,7 @@ struct service_process *service_process_create(struct service *service) static unsigned int uid_counter = 0; struct service_process *process; unsigned int uid = ++uid_counter; + const char *hostdomain; pid_t pid; bool process_forked; @@ -305,6 +307,9 @@ struct service_process *service_process_create(struct service *service) new processes now */ return NULL; } + /* look this up before fork()ing so that it gets cached for all the + future lookups. */ + hostdomain = my_hostdomain(); if (service->type == SERVICE_TYPE_ANVIL && service_anvil_global->pid != 0) { @@ -323,7 +328,7 @@ struct service_process *service_process_create(struct service *service) } if (pid == 0) { /* child */ - service_process_setup_environment(service, uid); + service_process_setup_environment(service, uid, hostdomain); service_reopen_inet_listeners(service); service_dup_fds(service); drop_privileges(service);