dovecot-2.0: master: If throttling a service and there are no se...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 20 10:25:50 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/2b5af8843142
changeset: 11344:2b5af8843142
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 20 09:15:49 2010 +0200
description:
master: If throttling a service and there are no service processes, drop all queued connection attempts.

diffstat:

 src/master/service-monitor.c |  19 +++++++++++--------
 src/master/service.c         |  22 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 8 deletions(-)

diffs (90 lines):

diff -r d1012db03a1c -r 2b5af8843142 src/master/service-monitor.c
--- 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)
diff -r d1012db03a1c -r 2b5af8843142 src/master/service.c
--- 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);


More information about the dovecot-cvs mailing list