chiark / gitweb /
[PATCH] klibc: version 1.0.4
[elogind.git] / udev_multiplex.c
index 6d7852d..9ab11e6 100644 (file)
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 
 #include "udev.h"
+#include "udev_libc_wrapper.h"
 #include "udev_utils.h"
 #include "logging.h"
 
@@ -72,23 +73,25 @@ static int run_program(struct udevice *udev, const char *filename)
  */
 void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix)
 {
-       char dirname[PATH_MAX];
+       char dirname[PATH_SIZE];
+       struct name_entry *name_loop, *name_tmp;
+       LIST_HEAD(name_list);
 
        /* chop the device name up into pieces based on '/' */
        if (udev->name[0] != '\0') {
-               char devname[NAME_SIZE];
+               char devname[PATH_SIZE];
                char *temp;
 
-               strfieldcpy(devname, udev->name);
+               strlcpy(devname, udev->name, sizeof(devname));
                temp = strchr(devname, '/');
                while (temp != NULL) {
                        temp[0] = '\0';
 
                        /* don't call the subsystem directory here */
                        if (strcmp(devname, udev->subsystem) != 0) {
-                               snprintf(dirname, PATH_MAX, "%s/%s", basedir, devname);
-                               dirname[PATH_MAX-1] = '\0';
-                               call_foreach_file(run_program, udev, dirname, suffix);
+                               snprintf(dirname, sizeof(dirname), "%s/%s", basedir, devname);
+                               dirname[sizeof(dirname)-1] = '\0';
+                               add_matching_files(&name_list, dirname, suffix);
                        }
 
                        temp[0] = '/';
@@ -98,18 +101,24 @@ void udev_multiplex_directory(struct udevice *udev, const char *basedir, const c
        }
 
        if (udev->name[0] != '\0') {
-               snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
-               dirname[PATH_MAX-1] = '\0';
-               call_foreach_file(run_program, udev, dirname, suffix);
+               snprintf(dirname, sizeof(dirname), "%s/%s", basedir, udev->name);
+               dirname[sizeof(dirname)-1] = '\0';
+               add_matching_files(&name_list, dirname, suffix);
        }
 
        if (udev->subsystem[0] != '\0') {
-               snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
-               dirname[PATH_MAX-1] = '\0';
-               call_foreach_file(run_program, udev, dirname, suffix);
+               snprintf(dirname, sizeof(dirname), "%s/%s", basedir, udev->subsystem);
+               dirname[sizeof(dirname)-1] = '\0';
+               add_matching_files(&name_list, dirname, suffix);
+       }
+
+       snprintf(dirname, sizeof(dirname), "%s/default", basedir);
+       dirname[sizeof(dirname)-1] = '\0';
+       add_matching_files(&name_list, dirname, suffix);
+
+       list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) {
+               run_program(udev, name_loop->name);
+               list_del(&name_loop->node);
        }
 
-       snprintf(dirname, PATH_MAX, "%s/default", basedir);
-       dirname[PATH_MAX-1] = '\0';
-       call_foreach_file(run_program, udev, dirname, suffix);
 }