]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
b237a168 | 2 | |
152d0efa | 3 | #include <errno.h> |
b237a168 ZJS |
4 | #include <string.h> |
5 | ||
152d0efa | 6 | #include "alloc-util.h" |
b237a168 ZJS |
7 | #include "fileio.h" |
8 | #include "log.h" | |
4b3ca79e | 9 | #include "parse-util.h" |
bc768f04 | 10 | #include "string-table.h" |
b237a168 ZJS |
11 | #include "string-util.h" |
12 | #include "udev-util.h" | |
4b3ca79e | 13 | #include "udev.h" |
b237a168 | 14 | |
bc768f04 ZJS |
15 | static const char* const resolve_name_timing_table[_RESOLVE_NAME_TIMING_MAX] = { |
16 | [RESOLVE_NAME_NEVER] = "never", | |
17 | [RESOLVE_NAME_LATE] = "late", | |
18 | [RESOLVE_NAME_EARLY] = "early", | |
19 | }; | |
20 | ||
21 | DEFINE_STRING_TABLE_LOOKUP(resolve_name_timing, ResolveNameTiming); | |
22 | ||
4b3ca79e ZJS |
23 | int udev_parse_config_full( |
24 | unsigned *ret_children_max, | |
25 | usec_t *ret_exec_delay_usec, | |
a14e7af1 ZJS |
26 | usec_t *ret_event_timeout_usec, |
27 | ResolveNameTiming *ret_resolve_name_timing) { | |
4b3ca79e | 28 | |
a14e7af1 | 29 | _cleanup_free_ char *log_val = NULL, *children_max = NULL, *exec_delay = NULL, *event_timeout = NULL, *resolve_names = NULL; |
b237a168 ZJS |
30 | int r; |
31 | ||
4b3ca79e ZJS |
32 | r = parse_env_file(NULL, "/etc/udev/udev.conf", NEWLINE, |
33 | "udev_log", &log_val, | |
34 | "children_max", &children_max, | |
35 | "exec_delay", &exec_delay, | |
36 | "event_timeout", &event_timeout, | |
37 | NULL); | |
38 | if (r == -ENOENT) | |
b237a168 ZJS |
39 | return 0; |
40 | if (r < 0) | |
41 | return r; | |
42 | ||
4b3ca79e ZJS |
43 | if (log_val) { |
44 | const char *log; | |
45 | size_t n; | |
46 | ||
47 | /* unquote */ | |
48 | n = strlen(log_val); | |
49 | if (n >= 2 && | |
50 | ((log_val[0] == '"' && log_val[n-1] == '"') || | |
51 | (log_val[0] == '\'' && log_val[n-1] == '\''))) { | |
52 | log_val[n - 1] = '\0'; | |
53 | log = log_val + 1; | |
54 | } else | |
55 | log = log_val; | |
56 | ||
57 | /* we set the udev log level here explicitly, this is supposed | |
58 | * to regulate the code in libudev/ and udev/. */ | |
59 | r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log); | |
60 | if (r < 0) | |
61 | log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log); | |
62 | } | |
63 | ||
64 | if (ret_children_max && children_max) { | |
65 | r = safe_atou(children_max, ret_children_max); | |
66 | if (r < 0) | |
67 | log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse children_max=%s, ignoring: %m", children_max); | |
68 | } | |
69 | ||
70 | if (ret_exec_delay_usec && exec_delay) { | |
71 | r = parse_sec(exec_delay, ret_exec_delay_usec); | |
72 | if (r < 0) | |
73 | log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse exec_delay=%s, ignoring: %m", exec_delay); | |
74 | } | |
75 | ||
76 | if (ret_event_timeout_usec && event_timeout) { | |
77 | r = parse_sec(event_timeout, ret_event_timeout_usec); | |
78 | if (r < 0) | |
79 | log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse event_timeout=%s, ignoring: %m", event_timeout); | |
80 | } | |
b237a168 | 81 | |
a14e7af1 ZJS |
82 | if (ret_resolve_name_timing && resolve_names) { |
83 | ResolveNameTiming t; | |
84 | ||
85 | t = resolve_name_timing_from_string(resolve_names); | |
86 | if (t < 0) | |
87 | log_notice("/etc/udev/udev.conf: failed to set parse resolve_names=%s, ignoring.", resolve_names); | |
88 | else | |
89 | *ret_resolve_name_timing = t; | |
90 | } | |
91 | ||
b237a168 ZJS |
92 | return 0; |
93 | } |