]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Rename unlang init functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 18 Mar 2021 20:57:29 +0000 (20:57 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 18 Mar 2021 20:57:29 +0000 (20:57 +0000)
src/bin/unit_test_attribute.c
src/bin/unit_test_module.c
src/lib/unlang/base.c
src/lib/unlang/base.h

index 3a599578b1c5c3533616b9e01fcbaacba8f03666..cfe8599cb7eeb717142db01a953642f59b634c17 100644 (file)
@@ -3121,7 +3121,10 @@ int main(int argc, char *argv[])
         *      Initialise the interpreter, registering operations.
         *      Needed because some keywords also register xlats.
         */
-       if (unlang_init() < 0) return -1;
+       if (unlang_init_global() < 0) {
+               fr_perror("unit_test_attribute");
+               EXIT_WITH_FAILURE;
+       }
 
        if (!xlat_register_legacy(inst, "test", xlat_test, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN)) {
                ERROR("Failed registering xlat");
@@ -3204,8 +3207,7 @@ cleanup:
                fr_perror("unit_test_attribute - dl_loader - ");        /* Print free order issues */
        }
        fr_dict_free(&config.dict);
-       unlang_free();
-       xlat_free();
+       unlang_free_global();
 
        /*
         *      Dictionaries get freed towards the end
index df2d0e926fee26c2ecb39d7142127c786d900327..2edadc0a9e72688fa94552268fed0a25f433198c 100644 (file)
@@ -800,8 +800,12 @@ int main(int argc, char *argv[])
 
        /*
         *      Initialise the interpreter, registering operations.
+        *      This initialises
         */
-       if (unlang_init() < 0) return -1;
+       if (unlang_init_global() < 0) {
+               fr_perror("%s", config->name);
+               EXIT_WITH_FAILURE;
+       }
 
        /*
         *      Ensure that we load the correct virtual server for the
@@ -1033,7 +1037,7 @@ cleanup:
        /*
         *      Free any resources used by the unlang interpreter.
         */
-       unlang_free();
+       unlang_free_global();
 
        /*
         *      And now nothing should be left anywhere except the
index 8ee7b23965f1f8a220aed6619e55dbdf6fd9c950..fbcead89e2b266a5681fe2916c33bac3174bf832 100644 (file)
@@ -28,6 +28,8 @@ RCSID("$Id$")
 
 #include "unlang_priv.h"
 
+static uint32_t instance_count;
+
 /** Return whether a section has unlang data associated with it
  *
  * @param[in] cs       to check.
@@ -65,18 +67,19 @@ void unlang_register(int type, unlang_op_t *op)
        memcpy(&unlang_ops[type], op, sizeof(unlang_ops[type]));
 }
 
-/** Initialize the unlang compiler / interpreter.
- *
- *  For now, just register the magic xlat function.
- */
-int unlang_init(void)
+int unlang_init_global(void)
 {
+       if (instance_count > 0) {
+               instance_count++;
+               return 0;
+       }
+
        /*
         *      Explicitly initialise the xlat tree, and perform dictionary lookups.
         */
        if (xlat_init() < 0) return -1;
 
-       unlang_interpret_init();
+       unlang_interpret_init_global();
        /* Register operations for the default keywords */
        unlang_condition_init();
        unlang_foreach_init();
@@ -98,6 +101,9 @@ int unlang_init(void)
 
 void unlang_free(void)
 {
+       if (--instance_count > 0) return;
+
        unlang_foreach_free();
        unlang_subrequest_op_free();
+       xlat_free();
 }
index 8856bd67efb9f3130bab38484061a5a2920b4e45..d27180fad5dda4f25331732f2db11d10384f46e5 100644 (file)
 extern "C" {
 #endif
 
-bool           unlang_section(CONF_SECTION *cs);
+bool                   unlang_section(CONF_SECTION *cs);
 
-int            unlang_init(void);
+int                    unlang_init_global(void);
+
+int                    unlang_free_global(void);
 
-void           unlang_free(void);
 
 #ifdef __cplusplus
 }