]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: move udev_parse_config_full() to udevd.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Jul 2023 21:44:37 +0000 (06:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 31 Jul 2023 14:23:00 +0000 (23:23 +0900)
Then, rename it to manager_parse_udev_config().

No functional change, just refactoring.

src/shared/udev-util.c
src/shared/udev-util.h
src/udev/udevd.c

index abf3c5e955a28e07837a224729bcd88929557baa..e1f31e52acb11d71807a85c0492c2503b2c3590c 100644 (file)
@@ -31,90 +31,43 @@ static const char* const resolve_name_timing_table[_RESOLVE_NAME_TIMING_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP(resolve_name_timing, ResolveNameTiming);
 
-int udev_parse_config_full(
-                unsigned *ret_children_max,
-                usec_t *ret_exec_delay_usec,
-                usec_t *ret_event_timeout_usec,
-                ResolveNameTiming *ret_resolve_name_timing,
-                int *ret_timeout_signal) {
-
-        _cleanup_free_ char *log_val = NULL, *children_max = NULL, *exec_delay = NULL, *event_timeout = NULL, *resolve_names = NULL, *timeout_signal = NULL;
-        int r;
+int udev_set_max_log_level(char *str) {
+        size_t n;
 
-        r = parse_env_file(NULL, "/etc/udev/udev.conf",
-                           "udev_log", &log_val,
-                           "children_max", &children_max,
-                           "exec_delay", &exec_delay,
-                           "event_timeout", &event_timeout,
-                           "resolve_names", &resolve_names,
-                           "timeout_signal", &timeout_signal);
-        if (r == -ENOENT)
-                return 0;
-        if (r < 0)
-                return r;
+        /* This may modify input string. */
 
-        if (log_val) {
-                const char *log;
-                size_t n;
-
-                /* unquote */
-                n = strlen(log_val);
-                if (n >= 2 &&
-                    ((log_val[0] == '"' && log_val[n-1] == '"') ||
-                     (log_val[0] == '\'' && log_val[n-1] == '\''))) {
-                        log_val[n - 1] = '\0';
-                        log = log_val + 1;
-                } else
-                        log = log_val;
-
-                /* we set the udev log level here explicitly, this is supposed
-                 * to regulate the code in libudev/ and udev/. */
-                r = log_set_max_level_from_string(log);
-                if (r < 0)
-                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                                   "failed to set udev log level '%s', ignoring: %m", log);
-        }
-
-        if (ret_children_max && children_max) {
-                r = safe_atou(children_max, ret_children_max);
-                if (r < 0)
-                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                                   "failed to parse children_max=%s, ignoring: %m", children_max);
-        }
+        if (isempty(str))
+                return 0;
 
-        if (ret_exec_delay_usec && exec_delay) {
-                r = parse_sec(exec_delay, ret_exec_delay_usec);
-                if (r < 0)
-                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                                   "failed to parse exec_delay=%s, ignoring: %m", exec_delay);
+        /* unquote */
+        n = strlen(str);
+        if (n >= 2 &&
+            ((str[0] == '"' && str[n - 1] == '"') ||
+             (str[0] == '\'' && str[n - 1] == '\''))) {
+                str[n - 1] = '\0';
+                str++;
         }
 
-        if (ret_event_timeout_usec && event_timeout) {
-                r = parse_sec(event_timeout, ret_event_timeout_usec);
-                if (r < 0)
-                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                                   "failed to parse event_timeout=%s, ignoring: %m", event_timeout);
-        }
+        /* we set the udev log level here explicitly, this is supposed
+         * to regulate the code in libudev/ and udev/. */
+        return log_set_max_level_from_string(str);
+}
 
-        if (ret_resolve_name_timing && resolve_names) {
-                ResolveNameTiming t;
+int udev_parse_config(void) {
+        _cleanup_free_ char *log_val = NULL;
+        int r;
 
-                t = resolve_name_timing_from_string(resolve_names);
-                if (t < 0)
-                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                                   "failed to parse resolve_names=%s, ignoring.", resolve_names);
-                else
-                        *ret_resolve_name_timing = t;
-        }
+        r = parse_env_file(NULL, "/etc/udev/udev.conf",
+                           "udev_log", &log_val);
+        if (r == -ENOENT)
+                return 0;
+        if (r < 0)
+                return r;
 
-        if (ret_timeout_signal && timeout_signal) {
-                r = signal_from_string(timeout_signal);
-                if (r < 0)
-                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
-                                   "failed to parse timeout_signal=%s, ignoring: %m", timeout_signal);
-                else
-                        *ret_timeout_signal = 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);
 
         return 0;
 }
index 97c14fb9bb6c18a238362d9affe20dd602d73fbe..77e3ee95b0effa072d48bf195139bfefb65c6e93 100644 (file)
@@ -20,16 +20,8 @@ typedef enum ResolveNameTiming {
 ResolveNameTiming resolve_name_timing_from_string(const char *s) _pure_;
 const char *resolve_name_timing_to_string(ResolveNameTiming i) _const_;
 
-int udev_parse_config_full(
-                unsigned *ret_children_max,
-                usec_t *ret_exec_delay_usec,
-                usec_t *ret_event_timeout_usec,
-                ResolveNameTiming *ret_resolve_name_timing,
-                int *ret_timeout_signal);
-
-static inline int udev_parse_config(void) {
-        return udev_parse_config_full(NULL, NULL, NULL, NULL, NULL);
-}
+int udev_set_max_log_level(char *str);
+int udev_parse_config(void);
 
 int device_wait_for_initialization(sd_device *device, const char *subsystem, usec_t timeout_usec, sd_device **ret);
 int device_wait_for_devlink(const char *path, const char *subsystem, usec_t timeout_usec, sd_device **ret);
index 588f8b3b568898f264cdaeb2da707770f685495a..d0856b4a55399d22757d1bfdfded3712575ef65f 100644 (file)
@@ -10,6 +10,7 @@
 #include "sd-daemon.h"
 
 #include "cpu-set-util.h"
+#include "env-file.h"
 #include "errno-util.h"
 #include "fd-util.h"
 #include "limits-util.h"
@@ -22,6 +23,7 @@
 #include "signal-util.h"
 #include "syslog-util.h"
 #include "udev-manager.h"
+#include "udev-util.h"
 #include "udevd.h"
 #include "version.h"
 
@@ -65,6 +67,74 @@ static int listen_fds(int *ret_ctrl, int *ret_netlink) {
         return 0;
 }
 
+static int manager_parse_udev_config(Manager *manager) {
+        _cleanup_free_ char *log_val = NULL, *children_max = NULL, *exec_delay = NULL,
+                *event_timeout = NULL, *resolve_names = NULL, *timeout_signal = NULL;
+        int r;
+
+        assert(manager);
+
+        r = parse_env_file(NULL, "/etc/udev/udev.conf",
+                           "udev_log", &log_val,
+                           "children_max", &children_max,
+                           "exec_delay", &exec_delay,
+                           "event_timeout", &event_timeout,
+                           "resolve_names", &resolve_names,
+                           "timeout_signal", &timeout_signal);
+        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 (children_max) {
+                r = safe_atou(children_max, &manager->children_max);
+                if (r < 0)
+                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
+                                   "Failed to parse children_max=%s, ignoring: %m", children_max);
+        }
+
+        if (exec_delay) {
+                r = parse_sec(exec_delay, &manager->exec_delay_usec);
+                if (r < 0)
+                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
+                                   "Failed to parse exec_delay=%s, ignoring: %m", exec_delay);
+        }
+
+        if (event_timeout) {
+                r = parse_sec(event_timeout, &manager->timeout_usec);
+                if (r < 0)
+                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
+                                   "Failed to parse event_timeout=%s, ignoring: %m", event_timeout);
+        }
+
+        if (resolve_names) {
+                ResolveNameTiming t;
+
+                t = resolve_name_timing_from_string(resolve_names);
+                if (t < 0)
+                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
+                                   "Failed to parse resolve_names=%s, ignoring.", resolve_names);
+                else
+                        manager->resolve_name_timing = t;
+        }
+
+        if (timeout_signal) {
+                r = signal_from_string(timeout_signal);
+                if (r < 0)
+                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
+                                   "Failed to parse timeout_signal=%s, ignoring: %m", timeout_signal);
+                else
+                        manager->timeout_signal = r;
+        }
+
+        return 0;
+}
+
 /*
  * read the kernel command line, in case we need to get into debug mode
  *   udev.log_level=<level>                    syslog priority
@@ -269,12 +339,7 @@ int run_udevd(int argc, char *argv[]) {
         if (!manager)
                 return log_oom();
 
-        udev_parse_config_full(
-                        &manager->children_max,
-                        &manager->exec_delay_usec,
-                        &manager->timeout_usec,
-                        &manager->resolve_name_timing,
-                        &manager->timeout_signal);
+        manager_parse_udev_config(manager);
 
         log_parse_environment();
         log_open(); /* Done again to update after reading configuration. */