]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/udev-util.c
udevd: allow more parameters to be set through udev.conf
[thirdparty/systemd.git] / src / shared / udev-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <string.h>
5
6 #include "alloc-util.h"
7 #include "fileio.h"
8 #include "log.h"
9 #include "parse-util.h"
10 #include "string-util.h"
11 #include "udev-util.h"
12 #include "udev.h"
13
14 int udev_parse_config_full(
15 unsigned *ret_children_max,
16 usec_t *ret_exec_delay_usec,
17 usec_t *ret_event_timeout_usec) {
18
19 _cleanup_free_ char *log_val = NULL, *children_max = NULL, *exec_delay = NULL, *event_timeout = NULL;
20 int r;
21
22 r = parse_env_file(NULL, "/etc/udev/udev.conf", NEWLINE,
23 "udev_log", &log_val,
24 "children_max", &children_max,
25 "exec_delay", &exec_delay,
26 "event_timeout", &event_timeout,
27 NULL);
28 if (r == -ENOENT)
29 return 0;
30 if (r < 0)
31 return r;
32
33 if (log_val) {
34 const char *log;
35 size_t n;
36
37 /* unquote */
38 n = strlen(log_val);
39 if (n >= 2 &&
40 ((log_val[0] == '"' && log_val[n-1] == '"') ||
41 (log_val[0] == '\'' && log_val[n-1] == '\''))) {
42 log_val[n - 1] = '\0';
43 log = log_val + 1;
44 } else
45 log = log_val;
46
47 /* we set the udev log level here explicitly, this is supposed
48 * to regulate the code in libudev/ and udev/. */
49 r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log);
50 if (r < 0)
51 log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log);
52 }
53
54 if (ret_children_max && children_max) {
55 r = safe_atou(children_max, ret_children_max);
56 if (r < 0)
57 log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse children_max=%s, ignoring: %m", children_max);
58 }
59
60 if (ret_exec_delay_usec && exec_delay) {
61 r = parse_sec(exec_delay, ret_exec_delay_usec);
62 if (r < 0)
63 log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse exec_delay=%s, ignoring: %m", exec_delay);
64 }
65
66 if (ret_event_timeout_usec && event_timeout) {
67 r = parse_sec(event_timeout, ret_event_timeout_usec);
68 if (r < 0)
69 log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse event_timeout=%s, ignoring: %m", event_timeout);
70 }
71
72 return 0;
73 }