]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Add automatic data stack frame to init unless disabled.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 3 Jun 2016 19:23:00 +0000 (22:23 +0300)
committerGitLab <gitlab@git.dovecot.net>
Mon, 6 Jun 2016 12:39:56 +0000 (15:39 +0300)
src/config/doveconf.c
src/lib-master/master-service.c
src/lib-master/master-service.h
src/master/main.c

index a07a2892485d33e40a2898045275ac26d2b777be..63ae419855754630927f960f3f88222c4bdcef1f 100644 (file)
@@ -701,6 +701,9 @@ static void failure_exit_callback(int *status)
 
 int main(int argc, char *argv[])
 {
+       enum master_service_flags master_service_flags =
+               MASTER_SERVICE_FLAG_STANDALONE |
+               MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME;
        enum config_dump_scope scope = CONFIG_DUMP_SCOPE_ALL;
        const char *orig_config_path, *config_path, *module;
        ARRAY(const char *) module_names;
@@ -720,8 +723,7 @@ int main(int argc, char *argv[])
        }
 
        memset(&filter, 0, sizeof(filter));
-       master_service = master_service_init("config",
-                                            MASTER_SERVICE_FLAG_STANDALONE,
+       master_service = master_service_init("config", master_service_flags,
                                             &argc, &argv, "adf:hHm:nNpPexS");
        orig_config_path = master_service_get_config_path(master_service);
 
index f0e5ffc1b92982317f3dd42333bc33299920e352..f907883bad66203f6a2a73ae820ebbfa62cde157 100644 (file)
@@ -182,6 +182,12 @@ master_service_init(const char *name, enum master_service_flags flags,
           is properly initialized */
        i_set_failure_prefix("%s(init): ", name);
 
+       /* make sure all the data stack allocations during init will be freed
+          before we get to ioloop. the corresponding t_pop() is in
+          master_service_init_finish(). */
+       if ((flags & MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME) == 0)
+               t_push(NULL);
+
        /* ignore these signals as early as possible */
        lib_signals_init();
         lib_signals_ignore(SIGPIPE, TRUE);
@@ -523,6 +529,10 @@ void master_service_init_finish(struct master_service *service)
                service->master_status.available_count--;
        }
        master_status_update(service);
+
+       /* close data stack frame opened by master_service_init() */
+       if ((service->flags & MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME) == 0)
+               t_pop();
 }
 
 void master_service_env_clean(void)
index 21ab957a3e9947a5b66cc49eb713aa0628191848..10e820316c81557532a7edf335dc0f9ceea47a5e 100644 (file)
@@ -32,7 +32,11 @@ enum master_service_flags {
           listeners (i.e. the service does STARTTLS). */
        MASTER_SERVICE_FLAG_USE_SSL_SETTINGS    = 0x200,
        /* Don't initialize SSL context automatically. */
-       MASTER_SERVICE_FLAG_NO_SSL_INIT         = 0x400
+       MASTER_SERVICE_FLAG_NO_SSL_INIT         = 0x400,
+       /* Don't create a data stack frame between master_service_init() and
+          master_service_init_finish(). By default this is done to make sure
+          initialization doesn't unnecessarily use up memory in data stack. */
+       MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME = 0x800
 };
 
 struct master_service_connection {
index 591194cd72e2ab305f43b81ae6e9e9878794097a..533d4d80566bfa73f26f32eb381e69441f6a30a5 100644 (file)
@@ -743,7 +743,8 @@ int main(int argc, char *argv[])
        }
        master_service = master_service_init(MASTER_SERVICE_NAME,
                                MASTER_SERVICE_FLAG_STANDALONE |
-                               MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR,
+                               MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR |
+                               MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME,
                                &argc, &argv, "+Fanp");
        i_unset_failure_prefix();