From: Timo Sirainen Date: Fri, 31 Mar 2023 12:32:17 +0000 (+0300) Subject: lib-master: Assert-crash if master_service_init_log*() is called before master_getopt() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9bbdf3ee6d506231c31773535a2818a07d922d28;p=thirdparty%2Fdovecot%2Fcore.git lib-master: Assert-crash if master_service_init_log*() is called before master_getopt() This makes sure that -L parameter will work for all services. --- diff --git a/src/lib-master/master-service-private.h b/src/lib-master/master-service-private.h index 4a75cf8e9f..bf7c53c72c 100644 --- a/src/lib-master/master-service-private.h +++ b/src/lib-master/master-service-private.h @@ -92,6 +92,7 @@ struct master_service { bool stopping:1; bool keep_environment:1; + bool options_parsed:1; bool log_directly:1; bool initial_status_sent:1; bool die_with_master:1; diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index abac39c034..5250dd4347 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -664,6 +664,7 @@ int master_getopt(struct master_service *service) i_assert(master_getopt_str_is_valid(service->getopt_str)); + service->options_parsed = TRUE; while ((c = getopt(service->argc, service->argv, service->getopt_str)) > 0) { if (!master_service_parse_option(service, c, optarg)) @@ -681,6 +682,7 @@ master_getopt_long(struct master_service *service, const char **longopt_r) i_assert(master_getopt_str_is_valid(service->getopt_str)); + service->options_parsed = TRUE; int c; int longopt_idx = -1; while ((c = getopt_long(service->argc, service->argv, @@ -719,6 +721,8 @@ master_service_try_init_log(struct master_service *service, { const char *timestamp; + i_assert(service->options_parsed); + if ((service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0 && (service->flags & MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR) == 0) { timestamp = getenv(DOVECOT_LOG_STDERR_TIMESTAMP_ENV);