mirror of
https://github.com/systemd/systemd.git
synced 2025-03-28 02:50:16 +03:00
udev-rules: check tokens order
When invoked by udevadm verify, warn about rules that have PROGRAM assignments specified after RESULT checks.
This commit is contained in:
parent
acbb504eaf
commit
56df2f6f9b
@ -1168,6 +1168,20 @@ static int parse_line(char **line, char **ret_key, char **ret_attr, UdevRuleOper
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void check_tokens_order(UdevRuleLine *rule_line) {
|
||||
bool has_result = false;
|
||||
|
||||
assert(rule_line);
|
||||
|
||||
LIST_FOREACH(tokens, t, rule_line->tokens)
|
||||
if (t->type == TK_M_RESULT)
|
||||
has_result = true;
|
||||
else if (has_result && t->type == TK_M_PROGRAM) {
|
||||
log_line_warning(rule_line, "Reordering RESULT check after PROGRAM assignment.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void sort_tokens(UdevRuleLine *rule_line) {
|
||||
assert(rule_line);
|
||||
|
||||
@ -1236,6 +1250,9 @@ static int rule_add_line(UdevRuleFile *rule_file, const char *line_str, unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (extra_checks)
|
||||
check_tokens_order(rule_line);
|
||||
|
||||
sort_tokens(rule_line);
|
||||
TAKE_PTR(rule_line);
|
||||
return 0;
|
||||
|
@ -300,6 +300,9 @@ test_syntax_error 'ACTION=="a" NAME="b"' 'A comma between tokens is expected.'
|
||||
test_syntax_error 'ACTION=="a",, NAME="b"' 'More than one comma between tokens.'
|
||||
test_syntax_error 'ACTION=="a" , NAME="b"' 'Stray whitespace before comma.'
|
||||
test_syntax_error 'ACTION=="a",NAME="b"' 'Whitespace after comma is expected.'
|
||||
test_syntax_error 'RESULT=="a", PROGRAM="b"' 'Reordering RESULT check after PROGRAM assignment.'
|
||||
test_syntax_error 'RESULT=="a*", PROGRAM="b", RESULT=="*c", PROGRAM="d"' \
|
||||
'Reordering RESULT check after PROGRAM assignment.'
|
||||
|
||||
cat >"${rules}" <<'EOF'
|
||||
KERNEL=="a|b", KERNEL=="a|c", NAME="d"
|
||||
@ -308,6 +311,7 @@ KERNEL!="a", KERNEL!="b", NAME="c"
|
||||
KERNEL=="|a", KERNEL=="|b", NAME="c"
|
||||
KERNEL=="*", KERNEL=="a*", NAME="b"
|
||||
KERNEL=="a*", KERNEL=="c*|ab*", NAME="d"
|
||||
PROGRAM="a", RESULT=="b"
|
||||
EOF
|
||||
assert_0 "${rules}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user