From: Arran Cudbard-Bell Date: Mon, 4 Oct 2021 18:11:06 +0000 (-0500) Subject: Add global atexit functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0411703647b7907ec394f73b54131f9585af269a;p=thirdparty%2Ffreeradius-server.git Add global atexit functions --- diff --git a/src/lib/util/atexit.c b/src/lib/util/atexit.c index 3606a35bdb..d9335fd5c8 100644 --- a/src/lib/util/atexit.c +++ b/src/lib/util/atexit.c @@ -194,6 +194,17 @@ int fr_atexit_global_setup(void) return 0; } +/** Add a free function to be called when the process exits + * + */ +int _atexit_global(NDEBUG_LOCATION_ARGS + fr_atexit_t func, void const *uctx) +{ + if (unlikely(atexit_entry_alloc(NDEBUG_LOCATION_VALS fr_atexit_global, func, uctx) == NULL)) return -1; + + return 0; +} + /** Add a new destructor * * @return diff --git a/src/lib/util/atexit.h b/src/lib/util/atexit.h index b911c23713..26af45f4f8 100644 --- a/src/lib/util/atexit.h +++ b/src/lib/util/atexit.h @@ -43,7 +43,20 @@ extern "C" { */ typedef void(*fr_atexit_t)(void *uctx); -int fr_atexit_global_setup(void); +int fr_atexit_global_setup(void); + +int _atexit_global(NDEBUG_LOCATION_ARGS fr_atexit_t func, void const *uctx); + +/** Add a free function to the global free list + * + * @param[in] func to call. + * @param[in] uctx to pass to func. + * @return + * - 0 on success. + * - -1 on failure. + */ +#define fr_atexit_global(_func, _uctx) \ + _atexit_global(NDEBUG_LOCATION_EXP _func, _uctx) /** Setup pair of global init/free functions * @@ -55,9 +68,10 @@ int fr_atexit_global_setup(void); * * Will not share init status outside of the function. * - * @param[in] _init function to call. Will be called once during the process - * lifetime. - * @param[in] _free function to call. Will be called once at exit. + * @param[in] _init function to call. Will be called once + * during the process lifetime. + * @param[in] _free function to call. Will be called once + * at exit. */ #define fr_atexit_global_once(_init, _free) \ { \