mirror of
https://github.com/systemd/systemd
synced 2026-03-19 19:44:48 +01:00
Compare commits
No commits in common. "56175bc45d3f2df02c02db1255a5c196e35cf45e" and "57ccd9f6c00bfe66efbfce87e47328a82606ff20" have entirely different histories.
56175bc45d
...
57ccd9f6c0
@ -1539,6 +1539,10 @@ static int udev_rule_apply_token_to_event(
|
|||||||
Hashmap *properties_list) {
|
Hashmap *properties_list) {
|
||||||
|
|
||||||
UdevRuleToken *token;
|
UdevRuleToken *token;
|
||||||
|
char buf[UDEV_PATH_SIZE];
|
||||||
|
const char *val;
|
||||||
|
size_t count;
|
||||||
|
bool match;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(rules);
|
assert(rules);
|
||||||
@ -1562,45 +1566,33 @@ static int udev_rule_apply_token_to_event(
|
|||||||
|
|
||||||
return token_match_string(token, device_action_to_string(a));
|
return token_match_string(token, device_action_to_string(a));
|
||||||
}
|
}
|
||||||
case TK_M_DEVPATH: {
|
case TK_M_DEVPATH:
|
||||||
const char *val;
|
|
||||||
|
|
||||||
r = sd_device_get_devpath(dev, &val);
|
r = sd_device_get_devpath(dev, &val);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_rule_error_errno(dev, rules, r, "Failed to get devpath: %m");
|
return log_rule_error_errno(dev, rules, r, "Failed to get devpath: %m");
|
||||||
|
|
||||||
return token_match_string(token, val);
|
return token_match_string(token, val);
|
||||||
}
|
|
||||||
case TK_M_KERNEL:
|
case TK_M_KERNEL:
|
||||||
case TK_M_PARENTS_KERNEL: {
|
case TK_M_PARENTS_KERNEL:
|
||||||
const char *val;
|
|
||||||
|
|
||||||
r = sd_device_get_sysname(dev, &val);
|
r = sd_device_get_sysname(dev, &val);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_rule_error_errno(dev, rules, r, "Failed to get sysname: %m");
|
return log_rule_error_errno(dev, rules, r, "Failed to get sysname: %m");
|
||||||
|
|
||||||
return token_match_string(token, val);
|
return token_match_string(token, val);
|
||||||
}
|
case TK_M_DEVLINK:
|
||||||
case TK_M_DEVLINK: {
|
|
||||||
const char *val;
|
|
||||||
|
|
||||||
FOREACH_DEVICE_DEVLINK(dev, val)
|
FOREACH_DEVICE_DEVLINK(dev, val)
|
||||||
if (token_match_string(token, strempty(startswith(val, "/dev/"))))
|
if (token_match_string(token, strempty(startswith(val, "/dev/"))))
|
||||||
return token->op == OP_MATCH;
|
return token->op == OP_MATCH;
|
||||||
return token->op == OP_NOMATCH;
|
return token->op == OP_NOMATCH;
|
||||||
}
|
|
||||||
case TK_M_NAME:
|
case TK_M_NAME:
|
||||||
return token_match_string(token, event->name);
|
return token_match_string(token, event->name);
|
||||||
case TK_M_ENV: {
|
case TK_M_ENV:
|
||||||
const char *val;
|
|
||||||
|
|
||||||
if (sd_device_get_property_value(dev, token->data, &val) < 0)
|
if (sd_device_get_property_value(dev, token->data, &val) < 0)
|
||||||
val = hashmap_get(properties_list, token->data);
|
val = hashmap_get(properties_list, token->data);
|
||||||
|
|
||||||
return token_match_string(token, val);
|
return token_match_string(token, val);
|
||||||
}
|
|
||||||
case TK_M_CONST: {
|
case TK_M_CONST: {
|
||||||
const char *val, *k = token->data;
|
const char *k = token->data;
|
||||||
|
|
||||||
if (streq(k, "arch"))
|
if (streq(k, "arch"))
|
||||||
val = architecture_to_string(uname_architecture());
|
val = architecture_to_string(uname_architecture());
|
||||||
@ -1611,18 +1603,13 @@ static int udev_rule_apply_token_to_event(
|
|||||||
return token_match_string(token, val);
|
return token_match_string(token, val);
|
||||||
}
|
}
|
||||||
case TK_M_TAG:
|
case TK_M_TAG:
|
||||||
case TK_M_PARENTS_TAG: {
|
case TK_M_PARENTS_TAG:
|
||||||
const char *val;
|
|
||||||
|
|
||||||
FOREACH_DEVICE_TAG(dev, val)
|
FOREACH_DEVICE_TAG(dev, val)
|
||||||
if (token_match_string(token, val))
|
if (token_match_string(token, val))
|
||||||
return token->op == OP_MATCH;
|
return token->op == OP_MATCH;
|
||||||
return token->op == OP_NOMATCH;
|
return token->op == OP_NOMATCH;
|
||||||
}
|
|
||||||
case TK_M_SUBSYSTEM:
|
case TK_M_SUBSYSTEM:
|
||||||
case TK_M_PARENTS_SUBSYSTEM: {
|
case TK_M_PARENTS_SUBSYSTEM:
|
||||||
const char *val;
|
|
||||||
|
|
||||||
r = sd_device_get_subsystem(dev, &val);
|
r = sd_device_get_subsystem(dev, &val);
|
||||||
if (r == -ENOENT)
|
if (r == -ENOENT)
|
||||||
val = NULL;
|
val = NULL;
|
||||||
@ -1630,11 +1617,8 @@ static int udev_rule_apply_token_to_event(
|
|||||||
return log_rule_error_errno(dev, rules, r, "Failed to get subsystem: %m");
|
return log_rule_error_errno(dev, rules, r, "Failed to get subsystem: %m");
|
||||||
|
|
||||||
return token_match_string(token, val);
|
return token_match_string(token, val);
|
||||||
}
|
|
||||||
case TK_M_DRIVER:
|
case TK_M_DRIVER:
|
||||||
case TK_M_PARENTS_DRIVER: {
|
case TK_M_PARENTS_DRIVER:
|
||||||
const char *val;
|
|
||||||
|
|
||||||
r = sd_device_get_driver(dev, &val);
|
r = sd_device_get_driver(dev, &val);
|
||||||
if (r == -ENOENT)
|
if (r == -ENOENT)
|
||||||
val = NULL;
|
val = NULL;
|
||||||
@ -1642,13 +1626,11 @@ static int udev_rule_apply_token_to_event(
|
|||||||
return log_rule_error_errno(dev, rules, r, "Failed to get driver: %m");
|
return log_rule_error_errno(dev, rules, r, "Failed to get driver: %m");
|
||||||
|
|
||||||
return token_match_string(token, val);
|
return token_match_string(token, val);
|
||||||
}
|
|
||||||
case TK_M_ATTR:
|
case TK_M_ATTR:
|
||||||
case TK_M_PARENTS_ATTR:
|
case TK_M_PARENTS_ATTR:
|
||||||
return token_match_attr(token, dev, event);
|
return token_match_attr(token, dev, event);
|
||||||
case TK_M_SYSCTL: {
|
case TK_M_SYSCTL: {
|
||||||
_cleanup_free_ char *value = NULL;
|
_cleanup_free_ char *value = NULL;
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false);
|
||||||
r = sysctl_read(sysctl_normalize(buf), &value);
|
r = sysctl_read(sysctl_normalize(buf), &value);
|
||||||
@ -1659,15 +1641,12 @@ static int udev_rule_apply_token_to_event(
|
|||||||
}
|
}
|
||||||
case TK_M_TEST: {
|
case TK_M_TEST: {
|
||||||
mode_t mode = PTR_TO_MODE(token->data);
|
mode_t mode = PTR_TO_MODE(token->data);
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
bool match;
|
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||||
if (!path_is_absolute(buf) &&
|
if (!path_is_absolute(buf) &&
|
||||||
udev_resolve_subsys_kernel(buf, buf, sizeof(buf), false) < 0) {
|
udev_resolve_subsys_kernel(buf, buf, sizeof(buf), false) < 0) {
|
||||||
char tmp[UDEV_PATH_SIZE];
|
char tmp[UDEV_PATH_SIZE];
|
||||||
const char *val;
|
|
||||||
|
|
||||||
r = sd_device_get_syspath(dev, &val);
|
r = sd_device_get_syspath(dev, &val);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -1693,8 +1672,7 @@ static int udev_rule_apply_token_to_event(
|
|||||||
return token->op == (match ? OP_MATCH : OP_NOMATCH);
|
return token->op == (match ? OP_MATCH : OP_NOMATCH);
|
||||||
}
|
}
|
||||||
case TK_M_PROGRAM: {
|
case TK_M_PROGRAM: {
|
||||||
char buf[UDEV_PATH_SIZE], result[UDEV_LINE_SIZE];
|
char result[UDEV_LINE_SIZE];
|
||||||
size_t count;
|
|
||||||
|
|
||||||
event->program_result = mfree(event->program_result);
|
event->program_result = mfree(event->program_result);
|
||||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||||
@ -1720,7 +1698,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
}
|
}
|
||||||
case TK_M_IMPORT_FILE: {
|
case TK_M_IMPORT_FILE: {
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||||
log_rule_debug(dev, rules, "Importing properties from '%s'", buf);
|
log_rule_debug(dev, rules, "Importing properties from '%s'", buf);
|
||||||
@ -1767,7 +1744,7 @@ static int udev_rule_apply_token_to_event(
|
|||||||
}
|
}
|
||||||
case TK_M_IMPORT_PROGRAM: {
|
case TK_M_IMPORT_PROGRAM: {
|
||||||
_cleanup_strv_free_ char **lines = NULL;
|
_cleanup_strv_free_ char **lines = NULL;
|
||||||
char buf[UDEV_PATH_SIZE], result[UDEV_LINE_SIZE], **line;
|
char result[UDEV_LINE_SIZE], **line;
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||||
log_rule_debug(dev, rules, "Importing properties from results of '%s'", buf);
|
log_rule_debug(dev, rules, "Importing properties from results of '%s'", buf);
|
||||||
@ -1812,7 +1789,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
UdevBuiltinCommand cmd = PTR_TO_UDEV_BUILTIN_CMD(token->data);
|
UdevBuiltinCommand cmd = PTR_TO_UDEV_BUILTIN_CMD(token->data);
|
||||||
assert(cmd >= 0 && cmd < _UDEV_BUILTIN_MAX);
|
assert(cmd >= 0 && cmd < _UDEV_BUILTIN_MAX);
|
||||||
unsigned mask = 1U << (int) cmd;
|
unsigned mask = 1U << (int) cmd;
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
|
|
||||||
if (udev_builtin_run_once(cmd)) {
|
if (udev_builtin_run_once(cmd)) {
|
||||||
/* check if we ran already */
|
/* check if we ran already */
|
||||||
@ -1838,8 +1814,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
return token->op == (r >= 0 ? OP_MATCH : OP_NOMATCH);
|
return token->op == (r >= 0 ? OP_MATCH : OP_NOMATCH);
|
||||||
}
|
}
|
||||||
case TK_M_IMPORT_DB: {
|
case TK_M_IMPORT_DB: {
|
||||||
const char *val;
|
|
||||||
|
|
||||||
if (!event->dev_db_clone)
|
if (!event->dev_db_clone)
|
||||||
return token->op == OP_NOMATCH;
|
return token->op == OP_NOMATCH;
|
||||||
r = sd_device_get_property_value(event->dev_db_clone, token->value, &val);
|
r = sd_device_get_property_value(event->dev_db_clone, token->value, &val);
|
||||||
@ -1874,8 +1848,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
return token->op == OP_MATCH;
|
return token->op == OP_MATCH;
|
||||||
}
|
}
|
||||||
case TK_M_IMPORT_PARENT: {
|
case TK_M_IMPORT_PARENT: {
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||||
r = import_parent_into_properties(dev, buf);
|
r = import_parent_into_properties(dev, buf);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -2034,9 +2006,9 @@ static int udev_rule_apply_token_to_event(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_A_ENV: {
|
case TK_A_ENV: {
|
||||||
const char *val, *name = token->data;
|
const char *name = token->data;
|
||||||
char value_new[UDEV_NAME_SIZE], *p = value_new;
|
char value_new[UDEV_NAME_SIZE], *p = value_new;
|
||||||
size_t count, l = sizeof(value_new);
|
size_t l = sizeof(value_new);
|
||||||
|
|
||||||
if (isempty(token->value)) {
|
if (isempty(token->value)) {
|
||||||
if (token->op == OP_ADD)
|
if (token->op == OP_ADD)
|
||||||
@ -2053,7 +2025,7 @@ static int udev_rule_apply_token_to_event(
|
|||||||
|
|
||||||
(void) udev_event_apply_format(event, token->value, p, l, false);
|
(void) udev_event_apply_format(event, token->value, p, l, false);
|
||||||
if (event->esc == ESCAPE_REPLACE) {
|
if (event->esc == ESCAPE_REPLACE) {
|
||||||
count = udev_replace_chars(p, NULL);
|
count = udev_replace_chars(buf, NULL);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
log_rule_debug(dev, rules, "Replaced %zu slash(es) from result of ENV{%s}%s=\"%s\"",
|
log_rule_debug(dev, rules, "Replaced %zu slash(es) from result of ENV{%s}%s=\"%s\"",
|
||||||
count, name, token->op == OP_ADD ? "+" : "", token->value);
|
count, name, token->op == OP_ADD ? "+" : "", token->value);
|
||||||
@ -2065,8 +2037,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_A_TAG: {
|
case TK_A_TAG: {
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||||
if (token->op == OP_ASSIGN)
|
if (token->op == OP_ASSIGN)
|
||||||
device_cleanup_tags(dev);
|
device_cleanup_tags(dev);
|
||||||
@ -2085,9 +2055,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_A_NAME: {
|
case TK_A_NAME: {
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
size_t count;
|
|
||||||
|
|
||||||
if (event->name_final)
|
if (event->name_final)
|
||||||
break;
|
break;
|
||||||
if (token->op == OP_ASSIGN_FINAL)
|
if (token->op == OP_ASSIGN_FINAL)
|
||||||
@ -2118,8 +2085,7 @@ static int udev_rule_apply_token_to_event(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_A_DEVLINK: {
|
case TK_A_DEVLINK: {
|
||||||
char buf[UDEV_PATH_SIZE], *p;
|
char *p;
|
||||||
size_t count;
|
|
||||||
|
|
||||||
if (event->devlink_final)
|
if (event->devlink_final)
|
||||||
break;
|
break;
|
||||||
@ -2163,8 +2129,8 @@ static int udev_rule_apply_token_to_event(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_A_ATTR: {
|
case TK_A_ATTR: {
|
||||||
char buf[UDEV_PATH_SIZE], value[UDEV_NAME_SIZE];
|
const char *key_name = token->data;
|
||||||
const char *val, *key_name = token->data;
|
char value[UDEV_NAME_SIZE];
|
||||||
|
|
||||||
if (udev_resolve_subsys_kernel(key_name, buf, sizeof(buf), false) < 0 &&
|
if (udev_resolve_subsys_kernel(key_name, buf, sizeof(buf), false) < 0 &&
|
||||||
sd_device_get_syspath(dev, &val) >= 0)
|
sd_device_get_syspath(dev, &val) >= 0)
|
||||||
@ -2188,7 +2154,7 @@ static int udev_rule_apply_token_to_event(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_A_SYSCTL: {
|
case TK_A_SYSCTL: {
|
||||||
char buf[UDEV_PATH_SIZE], value[UDEV_NAME_SIZE];
|
char value[UDEV_NAME_SIZE];
|
||||||
|
|
||||||
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false);
|
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false);
|
||||||
(void) udev_event_apply_format(event, token->value, value, sizeof(value), false);
|
(void) udev_event_apply_format(event, token->value, value, sizeof(value), false);
|
||||||
@ -2202,7 +2168,6 @@ static int udev_rule_apply_token_to_event(
|
|||||||
case TK_A_RUN_BUILTIN:
|
case TK_A_RUN_BUILTIN:
|
||||||
case TK_A_RUN_PROGRAM: {
|
case TK_A_RUN_PROGRAM: {
|
||||||
_cleanup_free_ char *cmd = NULL;
|
_cleanup_free_ char *cmd = NULL;
|
||||||
char buf[UDEV_PATH_SIZE];
|
|
||||||
|
|
||||||
if (event->run_final)
|
if (event->run_final)
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1162,21 +1162,6 @@ EOF
|
|||||||
rules => <<EOF
|
rules => <<EOF
|
||||||
ENV{WITH_WS}=" one two three "
|
ENV{WITH_WS}=" one two three "
|
||||||
SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
|
SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
|
||||||
EOF
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc => "symlink with env which contain slash (see #19309)",
|
|
||||||
devices => [
|
|
||||||
{
|
|
||||||
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
|
|
||||||
exp_links => ["first", "name-aaa_bbb_ccc-end",
|
|
||||||
"another_symlink", "a", "b", "c"],
|
|
||||||
not_exp_links => ["ame-aaa/bbb/ccc-end"],
|
|
||||||
}],
|
|
||||||
rules => <<EOF
|
|
||||||
ENV{WITH_SLASH}="aaa/bbb/ccc"
|
|
||||||
OPTIONS="string_escape=replace", ENV{REPLACED}="\$env{WITH_SLASH}"
|
|
||||||
SYMLINK=" first name-\$env{REPLACED}-end another_symlink a b c "
|
|
||||||
EOF
|
EOF
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user