From e5ca293fcd8f2b6c2d97bf00e55da9c1d7a53c40 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 4 Jun 2021 17:18:25 +0900 Subject: [PATCH] sd-device: set driver subsystem if the sd_device object is generated from nulstr Otherwise, the sd_device object cannot read correct udev database file. --- src/libsystemd/sd-device/device-internal.h | 1 + src/libsystemd/sd-device/device-private.c | 8 ++++++++ src/libsystemd/sd-device/sd-device.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/sd-device/device-internal.h b/src/libsystemd/sd-device/device-internal.h index 98446081579..19dac5c21f0 100644 --- a/src/libsystemd/sd-device/device-internal.h +++ b/src/libsystemd/sd-device/device-internal.h @@ -108,5 +108,6 @@ int device_set_devname(sd_device *device, const char *devname); int device_set_devtype(sd_device *device, const char *devtype); int device_set_devnum(sd_device *device, const char *major, const char *minor); int device_set_subsystem(sd_device *device, const char *_subsystem); +int device_set_drivers_subsystem(sd_device *device); int device_set_driver(sd_device *device, const char *_driver); int device_set_usec_initialized(sd_device *device, usec_t when); diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 3ede43f3775..3307bb9db61 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -382,12 +382,20 @@ void device_seal(sd_device *device) { } static int device_verify(sd_device *device) { + int r; + assert(device); if (!device->devpath || !device->subsystem || device->action < 0 || device->seqnum == 0) 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")) { + r = device_set_drivers_subsystem(device); + if (r < 0) + return r; + } + device->sealed = true; return 0; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index eff852c335f..ecb4c429c77 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -779,7 +779,7 @@ int device_set_subsystem(sd_device *device, const char *_subsystem) { return free_and_replace(device->subsystem, subsystem); } -static int device_set_drivers_subsystem(sd_device *device) { +int device_set_drivers_subsystem(sd_device *device) { _cleanup_free_ char *subsystem = NULL; const char *syspath, *drivers, *p; int r; -- 2.47.3