From ab7d939495241b7cd94cea3b6998d4fdd8fdf2d7 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 28 Aug 2026 14:51:57 +0200 Subject: [PATCH] Added ClearCleanupFunctions This function is useful when one wants to avoid a child process of inherting cleanup functions, such as avoiding up cleaning up the parent's PID file Signed-off-by: Victor Moene --- libutils/cleanup.c | 17 +++++++++++++++++ libutils/cleanup.h | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/libutils/cleanup.c b/libutils/cleanup.c index e8316775..eec6f6a4 100644 --- a/libutils/cleanup.c +++ b/libutils/cleanup.c @@ -72,3 +72,20 @@ void RegisterCleanupFunction(CleanupFn fn) pthread_mutex_unlock(&cleanup_functions_mutex); } +void ClearCleanupFunctions(void) +{ + pthread_mutex_lock(&cleanup_functions_mutex); + + CleanupList *p = cleanup_functions; + while (p) + { + CleanupList *cur = p; + p = cur->next; + free(cur); + } + + cleanup_functions = NULL; + + pthread_mutex_unlock(&cleanup_functions_mutex); +} + diff --git a/libutils/cleanup.h b/libutils/cleanup.h index 8cd59e0a..f71bb4fe 100644 --- a/libutils/cleanup.h +++ b/libutils/cleanup.h @@ -30,4 +30,9 @@ void CallCleanupFunctions(void); void DoCleanupAndExit(int ret) FUNC_ATTR_NORETURN; void RegisterCleanupFunction(CleanupFn fn); +/** + * Discards all currently registered cleanup functions without calling them. + */ +void ClearCleanupFunctions(void); + #endif