]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: lib - Support re-initialization
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 5 Dec 2025 21:19:20 +0000 (22:19 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 2 Feb 2026 18:54:43 +0000 (18:54 +0000)
src/lib/lib.c

index 4df939b7a19bdf23685782f259e6e342bc544b20..72b9eabbdf3fdd60625767ee524fcede0c5da1e5 100644 (file)
@@ -31,6 +31,7 @@ struct atexit_callback {
 };
 
 static ARRAY(struct atexit_callback) atexit_callbacks = ARRAY_INIT;
+static bool lib_registered_atexit = FALSE;
 static bool lib_clean_exit;
 
 /* The original faccessat() syscall didn't handle the flags parameter.  glibc
@@ -168,6 +169,9 @@ void lib_exit(int status)
 
 static void lib_atexit_handler(void)
 {
+       if (!lib_initialized)
+               return;
+
        /* We're already in exit code path. Avoid using any functions that
           might cause strange breakage. Especially anything that could call
           exit() again could cause infinite looping in some OSes. */
@@ -195,7 +199,10 @@ void lib_init(void)
           of using lib_exit(). master_service_init_finish() will change this
           again to be FALSE. */
        lib_set_clean_exit(TRUE);
-       atexit(lib_atexit_handler);
+       if (!lib_registered_atexit) {
+               atexit(lib_atexit_handler);
+               lib_registered_atexit = TRUE;
+       }
 
        lib_initialized = TRUE;
 }