- struct sysfs_attribute *attr;
- char value[VALUE_SIZE];
- size_t len;
-
- dlist_for_each_data(attr_list, attr, struct sysfs_attribute) {
- if (attr->value == NULL)
- continue;
- len = strlcpy(value, attr->value, sizeof(value));
- if (len >= sizeof(value)) {
- dbg("attribute value of '%s' too long, skip", attr->name);
- continue;
- }
+ char path[PATH_SIZE];
+ DIR *dir;
+ struct dirent *dent;
+
+ strlcpy(path, sysfs_path, sizeof(path));
+ strlcat(path, devpath, sizeof(path));
+
+ dir = opendir(path);
+ if (dir != NULL) {
+ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+ struct stat statbuf;
+ char filename[PATH_SIZE];
+ char *attr_value;
+ char value[NAME_SIZE];
+ size_t len;
+
+ if (dent->d_name[0] == '.')
+ continue;
+
+ strlcpy(filename, path, sizeof(filename));
+ strlcat(filename, "/", sizeof(filename));
+ strlcat(filename, dent->d_name, sizeof(filename));
+ if (lstat(filename, &statbuf) != 0)
+ continue;
+ if (S_ISLNK(statbuf.st_mode))
+ continue;
+
+ attr_value = sysfs_attr_get_value(devpath, dent->d_name);
+ if (attr_value == NULL)
+ continue;
+ len = strlcpy(value, attr_value, sizeof(value));
+ dbg("attr '%s'='%s'(%zi)", dent->d_name, value, len);
+
+ /* remove trailing newlines */
+ while (len && value[len-1] == '\n')
+ value[--len] = '\0';
+
+ /* skip nonprintable attributes */
+ while (len && isprint(value[len-1]))
+ len--;
+ if (len) {
+ dbg("attribute value of '%s' non-printable, skip", dent->d_name);
+ continue;
+ }