summaryrefslogtreecommitdiff
path: root/udev/udevadm-info.c
diff options
context:
space:
mode:
authorThomas Egerer <thomas.egerer@secunet.com>2011-03-04 17:06:43 +0100
committerKay Sievers <kay.sievers@vrfy.org>2011-03-04 21:51:32 +0100
commit95ce1875d79162324a5eb67f6a0ffbbdd5d29921 (patch)
tree4b3468665323231e6a508f4977656f557adbf931 /udev/udevadm-info.c
parentf180ad259f1480a3d58106e38eb760f79600e0e1 (diff)
libudev: use sysfs attr ilist interface for attribute walk
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
Diffstat (limited to 'udev/udevadm-info.c')
-rw-r--r--udev/udevadm-info.c72
1 files changed, 32 insertions, 40 deletions
diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c
index 4510f4aa90..f60ad2c450 100644
--- a/udev/udevadm-info.c
+++ b/udev/udevadm-info.c
@@ -33,47 +33,39 @@
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");
}