]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
master: host.domain lookups weren't cached, they were done at the worst possible...
authorTimo Sirainen <tss@iki.fi>
Thu, 10 Oct 2013 17:50:10 +0000 (20:50 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 10 Oct 2013 17:50:10 +0000 (20:50 +0300)
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).

src/master/service-process.c

index c3a5b87b6403afe493636ed71ccff657fe957c8e..73dd521cf5a4c09665229671e758dbdb50cee274 100644 (file)
@@ -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);