summaryrefslogtreecommitdiffstats
path: root/src/udev/udev-builtin-path_id.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev/udev-builtin-path_id.c')
-rw-r--r--src/udev/udev-builtin-path_id.c98
1 files changed, 39 insertions, 59 deletions
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
index 467c9a6..a23b32d 100644
--- a/src/udev/udev-builtin-path_id.c
+++ b/src/udev/udev-builtin-path_id.c
@@ -95,12 +95,7 @@ static sd_device *skip_subsystem(sd_device *dev, const char *subsys) {
*/
for (parent = dev; ; ) {
- const char *subsystem;
-
- if (sd_device_get_subsystem(parent, &subsystem) < 0)
- break;
-
- if (!streq(subsystem, subsys))
+ if (!device_in_subsystem(parent, subsys))
break;
dev = parent;
@@ -191,7 +186,7 @@ static sd_device *handle_scsi_sas(sd_device *parent, char **path) {
return NULL;
/* Check if we are simple disk */
- if (strncmp(phy_count, "1", 2) != 0)
+ if (!streq(phy_count, "1"))
return handle_scsi_sas_wide_port(parent, path);
/* Get connected phy */
@@ -417,10 +412,9 @@ static sd_device *handle_scsi_hyperv(sd_device *parent, char **path, size_t guid
}
static sd_device *handle_scsi(sd_device *parent, char **path, char **compat_path, bool *supported_parent) {
- const char *devtype, *id, *name;
+ const char *id, *name;
- if (sd_device_get_devtype(parent, &devtype) < 0 ||
- !streq(devtype, "scsi_device"))
+ if (!device_is_devtype(parent, "scsi_device"))
return parent;
/* firewire */
@@ -532,12 +526,10 @@ static int get_usb_revision(sd_device *dev) {
}
static sd_device *handle_usb(sd_device *parent, char **path) {
- const char *devtype, *str, *port;
+ const char *str, *port;
int r;
- if (sd_device_get_devtype(parent, &devtype) < 0)
- return parent;
- if (!STR_IN_SET(devtype, "usb_interface", "usb_device"))
+ if (!device_is_devtype(parent, "usb_interface") && !device_is_devtype(parent, "usb_device"))
return parent;
if (sd_device_get_sysname(parent, &str) < 0)
@@ -632,7 +624,7 @@ static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
return -ENXIO;
end += strspn(end, DIGITS);
- sysname = strndupa(sysname, end - sysname);
+ sysname = strndupa_safe(sysname, end - sysname);
r = sd_device_new_from_subsystem_sysname(&nvme, "nvme", sysname);
if (r < 0)
@@ -650,9 +642,8 @@ static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
return 0;
}
-static void add_id_with_usb_revision(sd_device *dev, bool test, char *path) {
+static void add_id_with_usb_revision(sd_device *dev, EventMode mode, char *path) {
char *p;
- int r;
assert(dev);
assert(path);
@@ -668,18 +659,15 @@ static void add_id_with_usb_revision(sd_device *dev, bool test, char *path) {
if (p[1] != '-')
return;
- r = udev_builtin_add_property(dev, test, "ID_PATH_WITH_USB_REVISION", path);
- if (r < 0)
- log_device_debug_errno(dev, r, "Failed to add ID_PATH_WITH_USB_REVISION property, ignoring: %m");
+ (void) udev_builtin_add_property(dev, mode, "ID_PATH_WITH_USB_REVISION", path);
/* Drop the USB revision specifier for backward compatibility. */
memmove(p - 1, p + 1, strlen(p + 1) + 1);
}
-static void add_id_tag(sd_device *dev, bool test, const char *path) {
+static void add_id_tag(sd_device *dev, EventMode mode, const char *path) {
char tag[UDEV_NAME_SIZE];
size_t i = 0;
- int r;
/* compose valid udev tag name */
for (const char *p = path; *p; p++) {
@@ -705,115 +693,111 @@ static void add_id_tag(sd_device *dev, bool test, const char *path) {
i--;
tag[i] = '\0';
- r = udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
- if (r < 0)
- log_device_debug_errno(dev, r, "Failed to add ID_PATH_TAG property, ignoring: %m");
+ (void) udev_builtin_add_property(dev, mode, "ID_PATH_TAG", tag);
}
-static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test) {
+static int builtin_path_id(UdevEvent *event, int argc, char *argv[]) {
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
_cleanup_(sd_device_unrefp) sd_device *dev_other_branch = NULL;
_cleanup_free_ char *path = NULL, *compat_path = NULL;
bool supported_transport = false, supported_parent = false;
- const char *subsystem;
int r;
/* walk up the chain of devices and compose path */
for (sd_device *parent = dev; parent; ) {
- const char *subsys, *sysname;
+ const char *sysname;
- if (sd_device_get_subsystem(parent, &subsys) < 0 ||
- sd_device_get_sysname(parent, &sysname) < 0) {
+ if (sd_device_get_sysname(parent, &sysname) < 0) {
;
- } else if (streq(subsys, "scsi_tape")) {
+ } else if (device_in_subsystem(parent, "scsi_tape")) {
handle_scsi_tape(parent, &path);
- } else if (streq(subsys, "scsi")) {
+ } else if (device_in_subsystem(parent, "scsi")) {
parent = handle_scsi(parent, &path, &compat_path, &supported_parent);
supported_transport = true;
- } else if (streq(subsys, "cciss")) {
+ } else if (device_in_subsystem(parent, "cciss")) {
parent = handle_cciss(parent, &path);
supported_transport = true;
- } else if (streq(subsys, "usb")) {
+ } else if (device_in_subsystem(parent, "usb")) {
parent = handle_usb(parent, &path);
supported_transport = true;
- } else if (streq(subsys, "bcma")) {
+ } else if (device_in_subsystem(parent, "bcma")) {
parent = handle_bcma(parent, &path);
supported_transport = true;
- } else if (streq(subsys, "serio")) {
+ } else if (device_in_subsystem(parent, "serio")) {
const char *sysnum;
if (sd_device_get_sysnum(parent, &sysnum) >= 0 && sysnum) {
path_prepend(&path, "serio-%s", sysnum);
parent = skip_subsystem(parent, "serio");
}
- } else if (streq(subsys, "pci")) {
+ } else if (device_in_subsystem(parent, "pci")) {
path_prepend(&path, "pci-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "pci-%s", sysname);
parent = skip_subsystem(parent, "pci");
supported_parent = true;
- } else if (streq(subsys, "platform")) {
+ } else if (device_in_subsystem(parent, "platform")) {
path_prepend(&path, "platform-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "platform-%s", sysname);
parent = skip_subsystem(parent, "platform");
supported_transport = true;
supported_parent = true;
- } else if (streq(subsys, "amba")) {
+ } else if (device_in_subsystem(parent, "amba")) {
path_prepend(&path, "amba-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "amba-%s", sysname);
parent = skip_subsystem(parent, "amba");
supported_transport = true;
supported_parent = true;
- } else if (streq(subsys, "acpi")) {
+ } else if (device_in_subsystem(parent, "acpi")) {
path_prepend(&path, "acpi-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "acpi-%s", sysname);
parent = skip_subsystem(parent, "acpi");
supported_parent = true;
- } else if (streq(subsys, "xen")) {
+ } else if (device_in_subsystem(parent, "xen")) {
path_prepend(&path, "xen-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "xen-%s", sysname);
parent = skip_subsystem(parent, "xen");
supported_parent = true;
- } else if (streq(subsys, "virtio")) {
+ } else if (device_in_subsystem(parent, "virtio")) {
parent = skip_subsystem(parent, "virtio");
supported_transport = true;
- } else if (streq(subsys, "scm")) {
+ } else if (device_in_subsystem(parent, "scm")) {
path_prepend(&path, "scm-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "scm-%s", sysname);
parent = skip_subsystem(parent, "scm");
supported_transport = true;
supported_parent = true;
- } else if (streq(subsys, "ccw")) {
+ } else if (device_in_subsystem(parent, "ccw")) {
path_prepend(&path, "ccw-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "ccw-%s", sysname);
parent = skip_subsystem(parent, "ccw");
supported_transport = true;
supported_parent = true;
- } else if (streq(subsys, "ccwgroup")) {
+ } else if (device_in_subsystem(parent, "ccwgroup")) {
path_prepend(&path, "ccwgroup-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "ccwgroup-%s", sysname);
parent = skip_subsystem(parent, "ccwgroup");
supported_transport = true;
supported_parent = true;
- } else if (streq(subsys, "ap")) {
+ } else if (device_in_subsystem(parent, "ap")) {
parent = handle_ap(parent, &path);
supported_transport = true;
supported_parent = true;
- } else if (streq(subsys, "iucv")) {
+ } else if (device_in_subsystem(parent, "iucv")) {
path_prepend(&path, "iucv-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "iucv-%s", sysname);
parent = skip_subsystem(parent, "iucv");
supported_transport = true;
supported_parent = true;
- } else if (STR_IN_SET(subsys, "nvme", "nvme-subsystem")) {
+ } else if (device_in_subsystem(parent, "nvme") || device_in_subsystem(parent, "nvme-subsystem")) {
const char *nsid;
if (sd_device_get_sysattr_value(dev, "nsid", &nsid) >= 0) {
@@ -821,7 +805,7 @@ static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test)
if (compat_path)
path_prepend(&compat_path, "nvme-%s", nsid);
- if (streq(subsys, "nvme-subsystem")) {
+ if (device_in_subsystem(parent, "nvme-subsystem")) {
r = find_real_nvme_parent(dev, &dev_other_branch);
if (r < 0)
return r;
@@ -833,7 +817,7 @@ static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test)
supported_parent = true;
supported_transport = true;
}
- } else if (streq(subsys, "spi")) {
+ } else if (device_in_subsystem(parent, "spi")) {
const char *sysnum;
if (sd_device_get_sysnum(parent, &sysnum) >= 0 && sysnum) {
@@ -864,18 +848,14 @@ static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test)
* devices do not expose their buses and do not provide a unique
* and predictable name that way.
*/
- if (sd_device_get_subsystem(dev, &subsystem) >= 0 &&
- streq(subsystem, "block") &&
- !supported_transport)
+ if (device_in_subsystem(dev, "block") && !supported_transport)
return -ENOENT;
- add_id_with_usb_revision(dev, test, path);
+ add_id_with_usb_revision(dev, event->event_mode, path);
- r = udev_builtin_add_property(dev, test, "ID_PATH", path);
- if (r < 0)
- log_device_debug_errno(dev, r, "Failed to add ID_PATH property, ignoring: %m");
+ (void) udev_builtin_add_property(dev, event->event_mode, "ID_PATH", path);
- add_id_tag(dev, test, path);
+ add_id_tag(dev, event->event_mode, path);
/*
* Compatible link generation for ATA devices
@@ -883,7 +863,7 @@ static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test)
* ID_PATH_ATA_COMPAT
*/
if (compat_path)
- udev_builtin_add_property(dev, test, "ID_PATH_ATA_COMPAT", compat_path);
+ (void) udev_builtin_add_property(dev, event->event_mode, "ID_PATH_ATA_COMPAT", compat_path);
return 0;
}