Mercurial > dovecot > core-2.2
changeset 11344:2b5af8843142 HEAD
master: If throttling a service and there are no service processes, drop all queued connection attempts.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 20 May 2010 09:15:49 +0200 |
parents | d1012db03a1c |
children | 01f81b9e9586 |
files | src/master/service-monitor.c src/master/service.c |
diffstat | 2 files changed, 33 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/master/service-monitor.c Wed May 19 18:49:25 2010 +0200 +++ b/src/master/service-monitor.c Thu May 20 09:15:49 2010 +0200 @@ -389,15 +389,15 @@ services_log_deinit(service_list); } -static void service_process_failure(struct service_process *process, int status) +static bool +service_process_failure(struct service_process *process, int status) { - struct service *service = process->service; + bool throttle; service_process_log_status_error(process, status); - if (process->total_count == 0) - service_monitor_throttle(service); - + throttle = process->total_count == 0; service_process_notify_add(service_anvil_global->kills, process); + return throttle; } void services_monitor_reap_children(void) @@ -406,7 +406,7 @@ struct service *service; pid_t pid; int status; - bool service_stopped; + bool service_stopped, throttle; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { process = hash_table_lookup(service_pids, &pid); @@ -421,14 +421,17 @@ /* success */ if (service->listen_pending) service_monitor_listen_start(service); + throttle = FALSE; } else { - service_process_failure(process, status); + throttle = service_process_failure(process, status); } - service_stopped = service->status_fd[0] == -1; if (service->type == SERVICE_TYPE_ANVIL) service_anvil_process_destroyed(process); service_process_destroy(process); + if (throttle) + service_monitor_throttle(service); + service_stopped = service->status_fd[0] == -1; if (!service_stopped) { service_monitor_start_extra_avail(service); if (service->to_throttle == NULL)
--- a/src/master/service.c Wed May 19 18:49:25 2010 +0200 +++ b/src/master/service.c Thu May 20 09:15:49 2010 +0200 @@ -611,11 +611,33 @@ service_monitor_listen_start(service); } +static void service_drop_listener_connections(struct service *service) +{ + struct service_listener *const *listenerp; + int fd; + + array_foreach(&service->listeners, listenerp) { + switch ((*listenerp)->type) { + case SERVICE_LISTENER_UNIX: + case SERVICE_LISTENER_INET: + while ((fd = net_accept((*listenerp)->fd, + NULL, NULL)) >= 0) + (void)close(fd); + break; + case SERVICE_LISTENER_FIFO: + break; + } + } +} + void service_throttle(struct service *service, unsigned int secs) { if (service->to_throttle != NULL) return; + if (service->processes == NULL) + service_drop_listener_connections(service); + service_monitor_listen_stop(service); service->to_throttle = timeout_add(secs * 1000, service_throttle_timeout, service);