From: Lennart Poettering Date: Tue, 12 Apr 2022 13:45:48 +0000 (+0200) Subject: sd-device: properly support some corner case syspath X-Git-Tag: v251-rc2~131^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0b859c9773a14f12d512447c27e3caf274456498;p=thirdparty%2Fsystemd.git sd-device: properly support some corner case syspath --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index ac4a538afa7..fb50a688b08 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -439,7 +439,10 @@ _public_ int sd_device_new_from_subsystem_sysname( const char *subsys = memdupa_suffix0(sysname, sep - sysname); sep++; - r = device_strjoin_new("/sys/bus/", subsys, "/drivers/", sep, ret); + if (streq(sep, "drivers")) /* If the sysname is "drivers", then it's the drivers directory itself that is meant. */ + r = device_strjoin_new("/sys/bus/", subsys, "/drivers", NULL, ret); + else + r = device_strjoin_new("/sys/bus/", subsys, "/drivers/", sep, ret); if (r < 0) return r; if (r > 0) @@ -940,6 +943,8 @@ int device_set_drivers_subsystem(sd_device *device) { return r; drivers = strstr(devpath, "/drivers/"); + if (!drivers) + drivers = endswith(devpath, "/drivers"); if (!drivers) return -EINVAL; @@ -986,11 +991,11 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) { if (subsystem) r = device_set_subsystem(device, subsystem); /* use implicit names */ - else if (path_startswith(device->devpath, "/module/")) + else if (!isempty(path_startswith(device->devpath, "/module/"))) r = device_set_subsystem(device, "module"); - else if (strstr(syspath, "/drivers/")) + else if (strstr(syspath, "/drivers/") || endswith(syspath, "/drivers")) r = device_set_drivers_subsystem(device); - else if (PATH_STARTSWITH_SET(device->devpath, "/class/", "/bus/")) + else if (!isempty(PATH_STARTSWITH_SET(device->devpath, "/class/", "/bus/"))) r = device_set_subsystem(device, "subsystem"); else { device->subsystem_set = true;