]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-util: use config. parser to parse udev.conf
authorDavid Tardon <dtardon@redhat.com>
Fri, 5 Jan 2024 14:45:04 +0000 (15:45 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Jan 2024 20:11:14 +0000 (05:11 +0900)
src/shared/udev-util.c

index cf28ba864796d20704b9b70cd567e3851a73071d..5ea03d6740c86016eaa9118052fb2f1cf6d4fa0d 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "conf-parser.h"
 #include "device-nodes.h"
 #include "device-private.h"
 #include "device-util.h"
@@ -45,20 +46,27 @@ int udev_set_max_log_level(char *str) {
 }
 
 int udev_parse_config(void) {
-        _cleanup_free_ char *log_val = NULL;
-        int r;
+        int r, log_val = -1;
+        const ConfigTableItem config_table[] = {
+                { NULL, "udev_log", config_parse_log_level, 0, &log_val },
+                {}
+        };
 
-        r = parse_env_file(NULL, "/etc/udev/udev.conf",
-                           "udev_log", &log_val);
+        r = config_parse_config_file_full(
+                        "udev.conf",
+                        "udev",
+                        /* sections = */ NULL,
+                        config_item_table_lookup,
+                        config_table,
+                        CONFIG_PARSE_WARN,
+                        /* userdata = */ NULL);
         if (r == -ENOENT)
                 return 0;
         if (r < 0)
                 return r;
 
-        r = udev_set_max_log_level(log_val);
-        if (r < 0)
-                log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                           "Failed to set udev log level '%s', ignoring: %m", log_val);
+        if (log_val >= 0)
+                log_set_max_level(log_val);
 
         return 0;
 }