Merge pull request #19312 from yuwata/udev-escape-slash-nvme
udev: make OPTIONS="string_escape=replace" take effect on ENV{key}= assiginment
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "format-util.h"
|
||||
#include "netif-naming-scheme.h"
|
||||
#include "netlink-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
@@ -848,6 +849,12 @@ static int rename_netif(UdevEvent *event) {
|
||||
if (r < 0)
|
||||
return log_device_error_errno(dev, r, "Failed to get ifindex: %m");
|
||||
|
||||
if (naming_scheme_has(NAMING_REPLACE_STRICTLY) &&
|
||||
!ifname_valid(event->name)) {
|
||||
log_device_warning(dev, "Invalid network interface name, ignoring: %s", event->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */
|
||||
r = device_add_property(dev, "ID_RENAMING", "1");
|
||||
if (r < 0)
|
||||
|
||||
+20
-10
@@ -17,6 +17,7 @@
|
||||
#include "glob-util.h"
|
||||
#include "list.h"
|
||||
#include "mkdir.h"
|
||||
#include "netif-naming-scheme.h"
|
||||
#include "nulstr-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
@@ -2023,6 +2024,12 @@ static int udev_rule_apply_token_to_event(
|
||||
l = strpcpyl(&p, l, val, " ", NULL);
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, p, l, false);
|
||||
if (event->esc == ESCAPE_REPLACE) {
|
||||
count = udev_replace_chars(buf, NULL);
|
||||
if (count > 0)
|
||||
log_rule_debug(dev, rules, "Replaced %zu slash(es) from result of ENV{%s}%s=\"%s\"",
|
||||
count, name, token->op == OP_ADD ? "+" : "", token->value);
|
||||
}
|
||||
|
||||
r = device_add_property(dev, name, value_new);
|
||||
if (r < 0)
|
||||
@@ -2053,21 +2060,23 @@ static int udev_rule_apply_token_to_event(
|
||||
if (token->op == OP_ASSIGN_FINAL)
|
||||
event->name_final = true;
|
||||
|
||||
if (sd_device_get_ifindex(dev, NULL) < 0) {
|
||||
log_rule_error(dev, rules,
|
||||
"Only network interface can be renamed, ignoring NAME=\"%s\"; please fix it.",
|
||||
token->value);
|
||||
break;
|
||||
}
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
|
||||
if (IN_SET(event->esc, ESCAPE_UNSET, ESCAPE_REPLACE)) {
|
||||
count = udev_replace_chars(buf, "/");
|
||||
if (naming_scheme_has(NAMING_REPLACE_STRICTLY))
|
||||
count = udev_replace_ifname(buf);
|
||||
else
|
||||
count = udev_replace_chars(buf, "/");
|
||||
if (count > 0)
|
||||
log_rule_debug(dev, rules, "Replaced %zu character(s) from result of NAME=\"%s\"",
|
||||
count, token->value);
|
||||
}
|
||||
if (sd_device_get_devnum(dev, NULL) >= 0 &&
|
||||
(sd_device_get_devname(dev, &val) < 0 ||
|
||||
!streq_ptr(buf, path_startswith(val, "/dev/")))) {
|
||||
log_rule_error(dev, rules,
|
||||
"Kernel device nodes cannot be renamed, ignoring NAME=\"%s\"; please fix it.",
|
||||
token->value);
|
||||
break;
|
||||
}
|
||||
r = free_and_strdup_warn(&event->name, buf);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -2096,7 +2105,8 @@ static int udev_rule_apply_token_to_event(
|
||||
else
|
||||
count = 0;
|
||||
if (count > 0)
|
||||
log_rule_debug(dev, rules, "Replaced %zu character(s) from result of LINK", count);
|
||||
log_rule_debug(dev, rules, "Replaced %zu character(s) from result of SYMLINK=\"%s\"",
|
||||
count, token->value);
|
||||
|
||||
p = skip_leading_chars(buf, NULL);
|
||||
while (!isempty(p)) {
|
||||
|
||||
Reference in New Issue
Block a user