]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Assert-crash if master_service_init_log*() is called before master_getopt()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 31 Mar 2023 12:32:17 +0000 (15:32 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 1 Oct 2025 08:18:30 +0000 (08:18 +0000)
This makes sure that -L parameter will work for all services.

src/lib-master/master-service-private.h
src/lib-master/master-service.c

index 4a75cf8e9fe8735359b3389bbaa69140e8d1433e..bf7c53c72c089ed5be40cf8cb4d53d2b7b7be60f 100644 (file)
@@ -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;
index abac39c034ebd6cb04555fd5b4edabc95eb205ac..5250dd4347ef1cbb0b67d0069f122f47f4b7ef62 100644 (file)
@@ -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);