chiark / gitweb /
no newline in log messages
[elogind.git] / udevtrigger.c
index c5d88b9ee0087e841bf7ca4a18a4b53d3061a683..3b5be2006e5de952bd2343e5489b8b22fa6bdae6 100644 (file)
@@ -118,12 +118,12 @@ static void trigger_uevent(const char *devpath)
 
        fd = open(filename, O_WRONLY);
        if (fd < 0) {
-               dbg("error on opening %s: %s\n", filename, strerror(errno));
+               dbg("error on opening %s: %s", filename, strerror(errno));
                return;
        }
 
        if (write(fd, "add", 3) < 0)
-               info("error on triggering %s: %s\n", filename, strerror(errno));
+               info("error on triggering %s: %s", filename, strerror(errno));
 
        close(fd);
 }
@@ -237,14 +237,15 @@ static int attr_filtered(const char *path)
        return 0;
 }
 
-static void scan_bus(void)
+static void scan_subsystem(const char *subsys)
 {
        char base[PATH_SIZE];
        DIR *dir;
        struct dirent *dent;
 
        strlcpy(base, sysfs_path, sizeof(base));
-       strlcat(base, "/bus", sizeof(base));
+       strlcat(base, "/", sizeof(base));
+       strlcat(base, subsys, sizeof(base));
 
        dir = opendir(base);
        if (dir != NULL) {
@@ -292,13 +293,6 @@ static void scan_block(void)
        char base[PATH_SIZE];
        DIR *dir;
        struct dirent *dent;
-       struct stat statbuf;
-
-       /* skip if "block" is already a "class" */
-       strlcpy(base, sysfs_path, sizeof(base));
-       strlcat(base, "/class/block", sizeof(base));
-       if (stat(base, &statbuf) == 0)
-               return;
 
        if (subsystem_filtered("block"))
                return;
@@ -321,7 +315,7 @@ static void scan_block(void)
                        strlcat(dirname, dent->d_name, sizeof(dirname));
                        if (attr_filtered(dirname))
                                continue;
-                       if (device_list_insert(dirname) != 0);
+                       if (device_list_insert(dirname) != 0)
                                continue;
 
                        /* look for partitions */
@@ -413,22 +407,14 @@ static void scan_failed(void)
        if (dir != NULL) {
                for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
                        char device[PATH_SIZE];
-                       size_t start, end, i;
+                       size_t start;
 
                        if (dent->d_name[0] == '.')
                                continue;
 
-                       strlcpy(device, sysfs_path, sizeof(device));
-                       start = strlcat(device, "/", sizeof(device));
-                       end = strlcat(device, dent->d_name, sizeof(device));
-                       if (end > sizeof(device))
-                               end = sizeof(device);
-
-                       /* replace PATH_TO_NAME_CHAR with '/' */
-                       for (i = start; i < end; i++)
-                               if (device[i] == PATH_TO_NAME_CHAR)
-                                       device[i] = '/';
-
+                       start = strlcpy(device, sysfs_path, sizeof(device));
+                       strlcat(device, dent->d_name, sizeof(device));
+                       path_decode(&device[start]);
                        device_list_insert(device);
                }
                closedir(dir);
@@ -506,9 +492,24 @@ int main(int argc, char *argv[], char *envp[])
        if (failed)
                scan_failed();
        else {
-               scan_bus();
-               scan_class();
-               scan_block();
+               char base[PATH_SIZE];
+               struct stat statbuf;
+
+               /* if we have /sys/subsystem, forget all the old stuff */
+               strlcpy(base, sysfs_path, sizeof(base));
+               strlcat(base, "/subsystem", sizeof(base));
+               if (stat(base, &statbuf) == 0)
+                       scan_subsystem("subsystem");
+               else {
+                       scan_subsystem("bus");
+                       scan_class();
+
+                       /* scan "block" if it isn't a "class" */
+                       strlcpy(base, sysfs_path, sizeof(base));
+                       strlcat(base, "/class/block", sizeof(base));
+                       if (stat(base, &statbuf) != 0)
+                               scan_block();
+               }
        }
        exec_list();