From: Timo Sirainen Date: Sat, 10 Oct 2009 01:02:56 +0000 (-0400) Subject: lib-master: Timeout reading configuration after 10 seconds. X-Git-Tag: 2.0.alpha1~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=27ca0e561c70933da8834e57f967dee9b41896ba;p=thirdparty%2Fdovecot%2Fcore.git lib-master: Timeout reading configuration after 10 seconds. --HG-- branch : HEAD --- diff --git a/src/lib-master/master-service-settings.c b/src/lib-master/master-service-settings.c index 1255714872..ab94bf2772 100644 --- a/src/lib-master/master-service-settings.c +++ b/src/lib-master/master-service-settings.c @@ -12,10 +12,12 @@ #include #include #include +#include #include #define DOVECOT_CONFIG_BIN_PATH BINDIR"/doveconf" +#define CONFIG_READ_TIMEOUT_SECS 10 #define CONFIG_HANDSHAKE "VERSION\tconfig\t1\t0\n" #undef DEF @@ -184,10 +186,11 @@ int master_service_settings_read(struct master_service *service, const struct setting_parser_info *tmp_root; struct setting_parser_context *parser; struct istream *istream; - const char *path, *error, *env, *const *keys; + const char *path = NULL, *error, *env, *const *keys; void **sets; unsigned int i; int ret, fd = -1; + time_t now, timeout; if (getenv("DOVECONF_ENV") == NULL && !service->default_settings) { path = input->config_path != NULL ? input->config_path : @@ -225,12 +228,26 @@ int master_service_settings_read(struct master_service *service, if (fd != -1) { istream = i_stream_create_fd(fd, (size_t)-1, FALSE); - istream->blocking = TRUE; /* fd is blocking */ - ret = settings_parse_stream_read(parser, istream); + now = time(NULL); + timeout = now + CONFIG_READ_TIMEOUT_SECS; + do { + alarm(timeout - now); + ret = settings_parse_stream_read(parser, istream); + alarm(0); + if (ret <= 0) + break; + + /* most likely timed out, but just in case some other + signal was delivered early check if we need to + continue */ + now = time(NULL); + } while (now < timeout); i_stream_unref(&istream); - i_assert(ret <= 0); - if (ret < 0) { - *error_r = settings_parser_get_error(parser); + + if (ret != 0) { + *error_r = ret > 0 ? t_strdup_printf( + "Timeout reading config from %s", path) : + settings_parser_get_error(parser); (void)close(fd); return -1; }