return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
"sd-device: Device created from strv or nulstr lacks devpath, subsystem, action or seqnum.");
- if (streq(device->subsystem, "drivers")) {
+ if (device_in_subsystem(device, "drivers")) {
r = device_set_drivers_subsystem(device);
if (r < 0)
- return r;
+ return log_device_debug_errno(device, r,
+ "sd-device: Failed to set driver subsystem: %m");
}
device->sealed = true;
if (!device->device_id) {
_cleanup_free_ char *id = NULL;
- const char *subsystem;
dev_t devnum;
int ifindex, r;
- r = sd_device_get_subsystem(device, &subsystem);
- if (r < 0)
- return r;
-
if (sd_device_get_devnum(device, &devnum) >= 0) {
/* use dev_t — b259:131072, c254:0 */
if (asprintf(&id, "%c" DEVNUM_FORMAT_STR,
- streq(subsystem, "block") ? 'b' : 'c',
+ device_in_subsystem(device, "block") ? 'b' : 'c',
DEVNUM_FORMAT_VAL(devnum)) < 0)
return -ENOMEM;
} else if (sd_device_get_ifindex(device, &ifindex) >= 0) {
if (r == O_DIRECTORY)
return -EINVAL;
- if (streq(subsystem, "drivers")) {
+ if (device_in_subsystem(device, "drivers"))
/* the 'drivers' pseudo-subsystem is special, and needs the real
* subsystem encoded as well */
- assert(device->driver_subsystem);
- id = strjoin("+drivers:", device->driver_subsystem, ":", sysname);
- } else
+ id = strjoin("+drivers:", ASSERT_PTR(device->driver_subsystem), ":", sysname);
+ else {
+ const char *subsystem;
+ r = sd_device_get_subsystem(device, &subsystem);
+ if (r < 0)
+ return r;
+
id = strjoin("+", subsystem, ":", sysname);
+ }
if (!id)
return -ENOMEM;
}