chiark / gitweb /
more merge fixups, looks like i missed a selinux patch somewhere...
[elogind.git] / udev_db.c
index 61d4b130d35f0e64aeb82b3189deaf108a5d346a..a423247d6b1074b1c1530cc12990fdb5462fbcd6 100644 (file)
--- a/udev_db.c
+++ b/udev_db.c
@@ -153,6 +153,7 @@ static int parse_db_file(struct udevice *udev, const char *filename)
                        break;
                }
        }
+       file_unmap(buf, bufsize);
 
        if (udev->name[0] == '\0')
                return -1;
@@ -239,3 +240,38 @@ found:
 
        return 0;
 }
+
+int udev_db_call_foreach(int (*handler_function)(struct udevice *udev))
+{
+       struct dirent *ent;
+       DIR *dir;
+       char filename[NAME_SIZE];
+       struct udevice db_udev;
+
+       dir = opendir(udev_db_path);
+       if (dir == NULL) {
+               dbg("unable to udev db '%s'", udev_db_path);
+               return -1;
+       }
+
+       while (1) {
+               ent = readdir(dir);
+               if (ent == NULL || ent->d_name[0] == '\0')
+                       break;
+
+               if (ent->d_name[0] == '.')
+                       continue;
+
+               snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name);
+               filename[NAME_SIZE-1] = '\0';
+
+               memset(&db_udev, 0x00, sizeof(struct udevice));
+               if (parse_db_file(&db_udev, filename) == 0) {
+                       if (handler_function(&db_udev) != 0)
+                               break;
+               }
+       }
+
+       closedir(dir);
+       return 0;
+}