]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libsystemd: sd-device - translate / vs. ! in sysname 1466/head
authorKay Sievers <kay@vrfy.org>
Mon, 5 Oct 2015 22:41:32 +0000 (00:41 +0200)
committerKay Sievers <kay@vrfy.org>
Mon, 5 Oct 2015 22:41:32 +0000 (00:41 +0200)
The kernel replaces '/' in device names with '!', we translate that back
to '/' in sysname, when taking sysname as input, we should translate it
back again.

src/libsystemd/sd-device/sd-device.c

index c528a157c14b627352850862f65be3901ffe227c..e46546ed91e17d6338452588f1b33e4b0086d31f 100644 (file)
@@ -295,15 +295,27 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s
                 } else
                         return -EINVAL;
         } else {
-                syspath = strjoina("/sys/subsystem/", subsystem, "/devices/", sysname);
+                char *name;
+                size_t len = 0;
+
+                /* translate sysname back to sysfs filename */
+                name = strdupa(sysname);
+                while (name[len] != '\0') {
+                        if (name[len] == '/')
+                                name[len] = '!';
+
+                        len ++;
+                }
+
+                syspath = strjoina("/sys/subsystem/", subsystem, "/devices/", name);
                 if (access(syspath, F_OK) >= 0)
                         return sd_device_new_from_syspath(ret, syspath);
 
-                syspath = strjoina("/sys/bus/", subsystem, "/devices/", sysname);
+                syspath = strjoina("/sys/bus/", subsystem, "/devices/", name);
                 if (access(syspath, F_OK) >= 0)
                         return sd_device_new_from_syspath(ret, syspath);
 
-                syspath = strjoina("/sys/class/", subsystem, "/", sysname);
+                syspath = strjoina("/sys/class/", subsystem, "/", name);
                 if (access(syspath, F_OK) >= 0)
                         return sd_device_new_from_syspath(ret, syspath);
         }