From: Timo Sirainen Date: Mon, 31 Aug 2009 18:07:35 +0000 (-0400) Subject: Added service_count setting to limit how many requests a service can handle before... X-Git-Tag: 2.0.alpha1~213 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=788f275469ad9ed530e440d6690d0e4381a323b2;p=thirdparty%2Fdovecot%2Fcore.git Added service_count setting to limit how many requests a service can handle before dying. --HG-- branch : HEAD --- diff --git a/src/lib-master/master-interface.h b/src/lib-master/master-interface.h index 7b69006ecb..168c847ba0 100644 --- a/src/lib-master/master-interface.h +++ b/src/lib-master/master-interface.h @@ -77,6 +77,10 @@ struct master_auth_reply { master_status.available_count as specified in configuration file */ #define MASTER_CLIENT_LIMIT_ENV "CLIENT_LIMIT" +/* getenv(MASTER_SERVICE_COUNT_ENV) specifies how many client connections the + process can finish handling before it should kill itself. */ +#define MASTER_SERVICE_COUNT_ENV "SERVICE_COUNT" + /* getenv(MASTER_CONFIG_FILE_ENV) provides path to configuration file/socket */ #define MASTER_CONFIG_FILE_ENV "CONFIG_FILE" diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 25b409b730..750b490e6e 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -273,6 +273,13 @@ void master_service_init_finish(struct master_service *service) i_fatal(MASTER_CLIENT_LIMIT_ENV" not set"); master_service_set_client_limit(service, count); + /* set the default service count */ + value = getenv(MASTER_SERVICE_COUNT_ENV); + count = value == NULL ? 0 : + (unsigned int)strtoul(value, NULL, 10); + if (count > 0) + master_service_set_service_count(service, count); + /* start listening errors for status fd, it means master died */ service->io_status_error = io_add(MASTER_STATUS_FD, IO_ERROR, master_status_error, service); diff --git a/src/master/master-settings.c b/src/master/master-settings.c index 52b1b94b39..b075a758a0 100644 --- a/src/master/master-settings.c +++ b/src/master/master-settings.c @@ -102,6 +102,7 @@ static struct setting_define service_setting_defines[] = { DEF(SET_UINT, process_limit), DEF(SET_UINT, client_limit), + DEF(SET_UINT, service_count), DEF(SET_UINT, vsz_limit), DEFLIST(unix_listeners, "unix_listener", @@ -132,6 +133,7 @@ static struct service_settings service_default_settings = { MEMBER(process_limit) (unsigned int)-1, MEMBER(client_limit) 0, + MEMBER(service_count) 0, MEMBER(vsz_limit) 256, MEMBER(unix_listeners) ARRAY_INIT, diff --git a/src/master/master-settings.h b/src/master/master-settings.h index 0ed31ad822..081c5937d6 100644 --- a/src/master/master-settings.h +++ b/src/master/master-settings.h @@ -33,6 +33,7 @@ struct service_settings { unsigned int process_limit; unsigned int client_limit; + unsigned int service_count; unsigned int vsz_limit; ARRAY_TYPE(file_listener_settings) unix_listeners; diff --git a/src/master/service-process.c b/src/master/service-process.c index 0232c4bc2c..a5362be13b 100644 --- a/src/master/service-process.c +++ b/src/master/service-process.c @@ -401,8 +401,11 @@ service_process_setup_environment(struct service *service, unsigned int uid) /* fallback to default limit */ limit = service->set->master_set->default_client_limit; } - env_put(t_strdup_printf(MASTER_CLIENT_LIMIT_ENV"=%u", limit)); + if (service->set->service_count != 0) { + env_put(t_strdup_printf(MASTER_SERVICE_COUNT_ENV"=%u", + service->set->service_count)); + } env_put(t_strdup_printf(MASTER_UID_ENV"=%u", uid)); if (!service->set->master_set->version_ignore)