]> err.no Git - systemd/commitdiff
libudev: use sysfs attr ilist interface for attribute walk
authorThomas Egerer <thomas.egerer@secunet.com>
Fri, 4 Mar 2011 16:06:43 +0000 (17:06 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Fri, 4 Mar 2011 20:51:32 +0000 (21:51 +0100)
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
libudev/docs/libudev-sections.txt
udev/udevadm-info.c

index 7db9c1bba953353258b7d3696dd9ccd59926eff8..918344d941440522927a746a8af436e4a9e80207 100644 (file)
@@ -54,6 +54,7 @@ udev_device_get_driver
 udev_device_get_devnum
 udev_device_get_action
 udev_device_get_sysattr_value
+udev_device_get_sysattr_list_entry
 udev_device_get_seqnum
 udev_device_get_usec_since_initialized
 </SECTION>
index 4510f4aa907dc56a22544564ec1e10045046bf61..f60ad2c4506b727a3b4ee474fb91827c674c679c 100644 (file)
 
 static void print_all_attributes(struct udev_device *device, const char *key)
 {
-       struct udev *udev = udev_device_get_udev(device);
-       DIR *dir;
-       struct dirent *dent;
-
-       dir = opendir(udev_device_get_syspath(device));
-       if (dir != NULL) {
-               for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-                       struct stat statbuf;
-                       const char *value;
-                       size_t len;
-
-                       if (dent->d_name[0] == '.')
-                               continue;
-
-                       if (strcmp(dent->d_name, "uevent") == 0)
-                               continue;
-                       if (strcmp(dent->d_name, "dev") == 0)
-                               continue;
-
-                       if (fstatat(dirfd(dir), dent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0)
-                               continue;
-                       if (S_ISLNK(statbuf.st_mode))
-                               continue;
-
-                       value = udev_device_get_sysattr_value(device, dent->d_name);
-                       if (value == NULL)
-                               continue;
-                       dbg(udev, "attr '%s'='%s'\n", dent->d_name, value);
-
-                       /* skip nonprintable attributes */
-                       len = strlen(value);
-                       while (len > 0 && isprint(value[len-1]))
-                               len--;
-                       if (len > 0) {
-                               dbg(udev, "attribute value of '%s' non-printable, skip\n", dent->d_name);
-                               continue;
-                       }
-
-                       printf("    %s{%s}==\"%s\"\n", key, dent->d_name, value);
+       struct udev_list_entry *sysattr;
+
+       udev_list_entry_foreach(sysattr, udev_device_get_sysattr_list_entry(device)) {
+               const char *name;
+               const char *value;
+               size_t len;
+
+               /* skip symlinks */
+               if (0 == strcmp("s", udev_list_entry_get_value(sysattr)))
+                       continue;
+
+               name = udev_list_entry_get_name(sysattr);
+               if (strcmp(name, "uevent") == 0)
+                       continue;
+               if (strcmp(name, "dev") == 0)
+                       continue;
+
+               value = udev_device_get_sysattr_value(device, name);
+               if (value == NULL)
+                       continue;
+               dbg(udev_device_get_udev(device), "attr '%s'='%s'\n", name, value);
+
+               /* skip nonprintable attributes */
+               len = strlen(value);
+               while (len > 0 && isprint(value[len-1]))
+                       len--;
+               if (len > 0) {
+                       dbg(udev_device_get_udev(device),
+                                       "attribute value of '%s' non-printable, skip\n", name);
+                       continue;
                }
-               closedir(dir);
+
+               printf("    %s{%s}==\"%s\"\n", key, name, value);
        }
        printf("\n");
 }