]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/udev-util.c
udev: move udev cleanup functions from udev-util.h to udev.h
[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 "string-util.h"
10 #include "udev-util.h"
11
12 int udev_parse_config(void) {
13 _cleanup_free_ char *val = NULL;
14 const char *log;
15 size_t n;
16 int r;
17
18 r = parse_env_file(NULL, "/etc/udev/udev.conf", NEWLINE, "udev_log", &val, NULL);
19 if (r == -ENOENT || !val)
20 return 0;
21 if (r < 0)
22 return r;
23
24 /* unquote */
25 n = strlen(val);
26 if (n >= 2 &&
27 ((val[0] == '"' && val[n-1] == '"') ||
28 (val[0] == '\'' && val[n-1] == '\''))) {
29 val[n - 1] = '\0';
30 log = val + 1;
31 } else
32 log = val;
33
34 /* we set the udev log level here explicitly, this is supposed
35 * to regulate the code in libudev/ and udev/. */
36 r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log);
37 if (r < 0)
38 log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log);
39
40 return 0;
41 }