chiark / gitweb /
tree-wide: drop license boilerplate
[elogind.git] / src / shared / udev-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2017 Zbigniew JÄ™drzejewski-Szmek
6 ***/
7
8 #include <string.h>
9
10 #include "fileio.h"
11 #include "log.h"
12 #include "string-util.h"
13 #include "udev-util.h"
14
15 /// Additional includes needed by elogind
16 #include "alloc-util.h"
17
18 int udev_parse_config(void) {
19         _cleanup_free_ char *val = NULL;
20         const char *log;
21         size_t n;
22         int r;
23
24         r = parse_env_file("/etc/udev/udev.conf", NEWLINE, "udev_log", &val, NULL);
25         if (r == -ENOENT || !val)
26                 return 0;
27         if (r < 0)
28                 return r;
29
30         /* unquote */
31         n = strlen(val);
32         if (n >= 2 &&
33             ((val[0] == '"' && val[n-1] == '"') ||
34              (val[0] == '\'' && val[n-1] == '\''))) {
35                 val[n - 1] = '\0';
36                 log = val + 1;
37         } else
38                 log = val;
39
40         /* we set the udev log level here explicitly, this is supposed
41          * to regulate the code in libudev/ and udev/. */
42         r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log);
43         if (r < 0)
44                 log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log);
45
46         return 0;
47 }