udev-builtin-net_id: do not assume the current interface name is ethX

Otherwise, `udevadm test-builtin` does not work as expected.
This commit is contained in:
Yu Watanabe
2023-07-29 22:14:24 +09:00
parent 07e1841eb9
commit ded2b1d093
+21 -6
View File
@@ -501,9 +501,9 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
}
static int names_vio(sd_device *dev, const char *prefix, bool test) {
const char *syspath, *subsystem, *p, *s;
sd_device *parent;
unsigned busid, slotid, ethid;
const char *syspath, *subsystem;
unsigned slotid;
int r;
assert(dev);
@@ -531,12 +531,27 @@ static int names_vio(sd_device *dev, const char *prefix, bool test) {
if (r < 0)
return log_device_debug_errno(dev, r, "sd_device_get_syspath() failed: %m");
r = sscanf(syspath, "/sys/devices/vio/%4x%4x/net/eth%u", &busid, &slotid, &ethid);
log_device_debug(dev, "Parsing vio slot information from syspath \"%s\": %s",
syspath, r == 3 ? "success" : "failure");
if (r != 3)
p = path_startswith(syspath, "/sys/devices/vio/");
if (!p)
return -EINVAL;
r = path_find_first_component(&p, /* accept_dot_dot = */ false, &s);
if (r < 0)
return r;
if (r != 8)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"VIO bus ID and slot ID have invalid length: %s", syspath);
s = strndupa(s, 8);
if (!in_charset(s, HEXDIGITS))
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"VIO bus ID and slot ID contain invalid characters: %s", s);
/* Parse only slot ID (tha last 4 hexdigits). */
r = safe_atou_full(s + 4, 16, &slotid);
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to parse VIO slot from syspath \"%s\": %m", syspath);
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sv%u", prefix, slotid))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);