]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add global atexit functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 4 Oct 2021 18:11:06 +0000 (13:11 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 4 Oct 2021 19:47:56 +0000 (14:47 -0500)
src/lib/util/atexit.c
src/lib/util/atexit.h

index 3606a35bdb0e43180e6a3e52c8a43807a18aac91..d9335fd5c8a7ec8299303ae208c4327b9c70e508 100644 (file)
@@ -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
index b911c2371388c9c370e8419b7b47c6415903aaab..26af45f4f8e7965f5ac26fe7613aff56bc306519 100644 (file)
@@ -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) \
 { \