dovecot-2.0: lib-master: Close listener fds when we stop accepti...

dovecot at dovecot.org dovecot at dovecot.org
Mon Dec 14 03:48:49 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/32949365f28d
changeset: 10472:32949365f28d
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Dec 13 20:48:43 2009 -0500
description:
lib-master: Close listener fds when we stop accepting more connections.

diffstat:

1 file changed, 30 insertions(+)
src/lib-master/master-service.c |   30 ++++++++++++++++++++++++++++++

diffs (56 lines):

diff -r 484be10242a7 -r 32949365f28d src/lib-master/master-service.c
--- a/src/lib-master/master-service.c	Sun Dec 13 20:47:38 2009 -0500
+++ b/src/lib-master/master-service.c	Sun Dec 13 20:48:43 2009 -0500
@@ -38,6 +38,7 @@
 
 struct master_service *master_service;
 
+static void master_service_io_listeners_close(struct master_service *service);
 static void master_service_refresh_login_state(struct master_service *service);
 
 const char *master_service_getopt_string(void)
@@ -481,8 +482,12 @@ void master_service_stop_new_connections
 {
 	unsigned int current_count;
 
+	if (service->stopping)
+		return;
+
 	service->stopping = TRUE;
 	master_service_io_listeners_remove(service);
+	master_service_io_listeners_close(service);
 
 	/* make sure we stop after servicing current connections */
 	current_count = service->total_available_count -
@@ -745,6 +750,31 @@ void master_service_io_listeners_remove(
 		for (i = 0; i < service->socket_count; i++) {
 			if (service->listeners[i].io != NULL)
 				io_remove(&service->listeners[i].io);
+		}
+	}
+}
+
+static void master_service_io_listeners_close(struct master_service *service)
+{
+	unsigned int i;
+
+	if (service->listeners != NULL) {
+		/* close via listeners. some fds might be pipes that are
+		   currently handled as clients. we don't want to close them. */
+		for (i = 0; i < service->socket_count; i++) {
+			if (service->listeners[i].fd != -1) {
+				if (close(service->listeners[i].fd) < 0) {
+					i_error("close(listener %d) failed: %m",
+						service->listeners[i].fd);
+				}
+			}
+		}
+	} else {
+		for (i = 0; i < service->socket_count; i++) {
+			int fd = MASTER_LISTEN_FD_FIRST + i;
+
+			if (close(fd) < 0)
+				i_error("close(listener %d) failed: %m", fd);
 		}
 	}
 }


More information about the dovecot-cvs mailing list