From: Stephan Bosch Date: Fri, 5 Dec 2025 21:19:20 +0000 (+0100) Subject: lib: lib - Support re-initialization X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d744ee1effbfff44db235060eb2f27e2e933f00f;p=thirdparty%2Fdovecot%2Fcore.git lib: lib - Support re-initialization --- diff --git a/src/lib/lib.c b/src/lib/lib.c index 4df939b7a1..72b9eabbdf 100644 --- a/src/lib/lib.c +++ b/src/lib/lib.c @@ -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; }