1 |
commit: 14748acf5e6e11db07e61ac188d6d1e799f29c6a |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Feb 9 12:17:06 2021 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Feb 9 19:07:34 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/eudev.git/commit/?id=14748acf |
7 |
|
8 |
udevadm: hwdb: sync with systemd |
9 |
|
10 |
Backports some changes from https://github.com/systemd/systemd/commit/6a34639e76b8b59233a97533b13836d5a44e8d4a. |
11 |
|
12 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
13 |
Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org> |
14 |
|
15 |
src/udev/udevadm-hwdb.c | 44 +++++++++++++++++++++++++++++++------------- |
16 |
1 file changed, 31 insertions(+), 13 deletions(-) |
17 |
|
18 |
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c |
19 |
index 9df043835..6bc108783 100644 |
20 |
--- a/src/udev/udevadm-hwdb.c |
21 |
+++ b/src/udev/udevadm-hwdb.c |
22 |
@@ -426,21 +426,25 @@ static int insert_data(struct trie *trie, struct udev_list *match_list, |
23 |
char *value; |
24 |
struct udev_list_entry *entry; |
25 |
|
26 |
+ assert(line[0] == ' '); |
27 |
+ |
28 |
value = strchr(line, '='); |
29 |
if (!value) { |
30 |
- log_error("Error, key/value pair expected but got '%s' in '%s':", line, filename); |
31 |
+ log_error("Warning, key-value pair expected but got \"%s\", ignoring", line); |
32 |
return -EINVAL; |
33 |
} |
34 |
|
35 |
value[0] = '\0'; |
36 |
value++; |
37 |
|
38 |
- /* libudev requires properties to start with a space */ |
39 |
+ /* Replace multiple leading spaces by a single space */ |
40 |
while (isblank(line[0]) && isblank(line[1])) |
41 |
line++; |
42 |
|
43 |
- if (line[0] == '\0' || value[0] == '\0') { |
44 |
- log_error("Error, empty key or value '%s' in '%s':", line, filename); |
45 |
+ if (isempty(line + 1) || isempty(value)) { |
46 |
+ log_error("Warning, empty %s in \"%s=%s\", ignoring", |
47 |
+ isempty(line + 1) ? "key" : "value", |
48 |
+ line, value); |
49 |
return -EINVAL; |
50 |
} |
51 |
|
52 |
@@ -459,17 +463,21 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam |
53 |
FILE *f; |
54 |
char line[LINE_MAX]; |
55 |
struct udev_list match_list; |
56 |
+ uint32_t line_number = 0; |
57 |
+ int r = 0, err; |
58 |
|
59 |
udev_list_init(udev, &match_list, false); |
60 |
|
61 |
f = fopen(filename, "re"); |
62 |
- if (f == NULL) |
63 |
+ if (!f) |
64 |
return -errno; |
65 |
|
66 |
while (fgets(line, sizeof(line), f)) { |
67 |
size_t len; |
68 |
char *pos; |
69 |
|
70 |
+ ++line_number; |
71 |
+ |
72 |
/* comment line */ |
73 |
if (line[0] == '#') |
74 |
continue; |
75 |
@@ -491,7 +499,8 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam |
76 |
break; |
77 |
|
78 |
if (line[0] == ' ') { |
79 |
- log_error("Error, MATCH expected but got '%s' in '%s':", line, filename); |
80 |
+ log_error("Warning, match expected but got indented property \"%s\", ignoring line", line); |
81 |
+ r = -EINVAL; |
82 |
break; |
83 |
} |
84 |
|
85 |
@@ -502,46 +511,55 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam |
86 |
|
87 |
case HW_MATCH: |
88 |
if (len == 0) { |
89 |
- log_error("Error, DATA expected but got empty line in '%s':", filename); |
90 |
+ log_error("Warning, property expected, ignoring record with no properties"); |
91 |
+ r = -EINVAL; |
92 |
state = HW_NONE; |
93 |
udev_list_cleanup(&match_list); |
94 |
break; |
95 |
} |
96 |
|
97 |
- /* another match */ |
98 |
if (line[0] != ' ') { |
99 |
+ /* another match */ |
100 |
udev_list_entry_add(&match_list, line, NULL); |
101 |
break; |
102 |
} |
103 |
|
104 |
/* first data */ |
105 |
state = HW_DATA; |
106 |
- insert_data(trie, &match_list, line, filename); |
107 |
+ err = insert_data(trie, &match_list, line, filename); |
108 |
+ if (err < 0) |
109 |
+ r = err; |
110 |
break; |
111 |
|
112 |
case HW_DATA: |
113 |
- /* end of record */ |
114 |
if (len == 0) { |
115 |
+ /* end of record */ |
116 |
state = HW_NONE; |
117 |
udev_list_cleanup(&match_list); |
118 |
break; |
119 |
} |
120 |
|
121 |
if (line[0] != ' ') { |
122 |
- log_error("Error, DATA expected but got '%s' in '%s':", line, filename); |
123 |
+ log_error("Warning, property or empty line expected, got \"%s\", ignoring record", line); |
124 |
+ r = -EINVAL; |
125 |
state = HW_NONE; |
126 |
udev_list_cleanup(&match_list); |
127 |
break; |
128 |
} |
129 |
|
130 |
- insert_data(trie, &match_list, line, filename); |
131 |
+ err = insert_data(trie, &match_list, line, filename); |
132 |
+ if (err < 0) |
133 |
+ r = err; |
134 |
break; |
135 |
}; |
136 |
} |
137 |
|
138 |
+ if (state == HW_MATCH) |
139 |
+ log_error("Warning, property expected, ignoring record with no properties"); |
140 |
+ |
141 |
fclose(f); |
142 |
udev_list_cleanup(&match_list); |
143 |
- return 0; |
144 |
+ return r; |
145 |
} |
146 |
|
147 |
static void help(void) { |