]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
ulogd: provide default configure implementation
authorCorubba Smith <corubba@gmx.de>
Wed, 12 Mar 2025 14:55:55 +0000 (15:55 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 12 Mar 2025 15:28:51 +0000 (16:28 +0100)
Provide a default implementation for the configure hook which simply
calls ulogd_parse_configfile(), so simple plugins only need to provide
the config_keyset. This also triggers an "unknown key" error if a
plugin defines no config_keyset (aka it has no options), but the config
file contains directives for it.

Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/conffile.c
src/ulogd.c

index 955956ab27426f3e0114c9d9751d0270cc7e154f..e55ff30b2ac833878db4444f9c06bb7084b5cb1c 100644 (file)
@@ -158,7 +158,12 @@ int config_parse_file(const char *section, struct config_keyset *kset)
        }
 
        if (!found) {
-               err = -ERRSECTION;
+               if (kset->num_ces == 0) {
+                       /* If there are no options, then no section isnt an error. */
+                       err = 0;
+               } else {
+                       err = -ERRSECTION;
+               }
                goto cpf_error;
        }
 
index c844767ad7b3f274ebdc349490bcb12626709fb0..b146f94cc8e626066738120deb4d44be4964cb43 100644 (file)
@@ -856,19 +856,29 @@ create_stack_resolve_keys(struct ulogd_pluginstance_stack *stack)
 
        /* pre-configuration pass */
        llist_for_each_entry_reverse(pi_cur, &stack->list, list) {
+               int ret;
+
                ulogd_log(ULOGD_DEBUG, "traversing plugin `%s'\n", 
                          pi_cur->plugin->name);
                /* call plugin to tell us which keys it requires in
                 * given configuration */
                if (pi_cur->plugin->configure) {
-                       int ret = pi_cur->plugin->configure(pi_cur, 
-                                                           stack);
-                       if (ret < 0) {
-                               ulogd_log(ULOGD_ERROR, "error during "
-                                         "configure of plugin %s\n",
-                                         pi_cur->plugin->name);
-                               return ret;
-                       }
+                       ret = pi_cur->plugin->configure(pi_cur, stack);
+               } else {
+                       struct config_keyset empty_kset = {.num_ces=0};
+                       struct config_keyset *kset = &empty_kset;
+
+                       if (pi_cur->config_kset)
+                               kset = pi_cur->config_kset;
+
+                       ret = ulogd_parse_configfile(pi_cur->id, kset);
+               }
+
+               if (ret < 0) {
+                       ulogd_log(ULOGD_ERROR, "error during "
+                                 "configure of plugin %s\n",
+                                 pi_cur->plugin->name);
+                       return ret;
                }
        }