]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: properly support some corner case syspath
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2022 13:45:48 +0000 (15:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 Apr 2022 12:41:05 +0000 (14:41 +0200)
src/libsystemd/sd-device/sd-device.c

index ac4a538afa7ec71fd32f2822c62161d24deda4a1..fb50a688b080b5fcea4db8ee476d728a125acf4c 100644 (file)
@@ -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;