From: Thomas Egerer <thomas.egerer@secunet.com>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH 2/2] libudev: Use sysfs attr interface for attribute walk
Date: Fri, 04 Mar 2011 16:06:43 +0000 [thread overview]
Message-ID: <4D710E13.2000506@secunet.com> (raw)
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
---
libudev/docs/libudev-sections.txt | 1 +
udev/udevadm-info.c | 62 ++++++++++++++++---------------------
2 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/libudev/docs/libudev-sections.txt b/libudev/docs/libudev-sections.txt
index 7db9c1b..918344d 100644
--- a/libudev/docs/libudev-sections.txt
+++ b/libudev/docs/libudev-sections.txt
@@ -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>
diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c
index 4510f4a..f60ad2c 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");
}
reply other threads:[~2011-03-04 16:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D710E13.2000506@secunet.com \
--to=thomas.egerer@secunet.com \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).