mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
udevinfo: do not show symlinks as attributes in --attribute-walk
This commit is contained in:
parent
e136a3360b
commit
492e76c9c1
49
udev_sysfs.c
49
udev_sysfs.c
@ -397,28 +397,37 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
|
||||
attr->value = attr->value_local;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* read attribute value */
|
||||
fd = open(path_full, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
dbg("attribute '%s' does not exist", path_full);
|
||||
goto out;
|
||||
}
|
||||
size = read(fd, value, sizeof(value));
|
||||
close(fd);
|
||||
if (size < 0)
|
||||
goto out;
|
||||
if (size == sizeof(value))
|
||||
goto out;
|
||||
|
||||
/* got a valid value, store and return it */
|
||||
value[size] = '\0';
|
||||
remove_trailing_chars(value, '\n');
|
||||
dbg("cache '%s' with attribute value '%s'", path_full, value);
|
||||
strlcpy(attr->value_local, value, sizeof(attr->value_local));
|
||||
attr->value = attr->value_local;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* skip directories */
|
||||
if (S_ISDIR(statbuf.st_mode))
|
||||
goto out;
|
||||
|
||||
/* skip non-readable files */
|
||||
if ((statbuf.st_mode & S_IRUSR) == 0)
|
||||
goto out;
|
||||
|
||||
/* read attribute value */
|
||||
fd = open(path_full, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
dbg("attribute '%s' does not exist", path_full);
|
||||
goto out;
|
||||
}
|
||||
size = read(fd, value, sizeof(value));
|
||||
close(fd);
|
||||
if (size < 0)
|
||||
goto out;
|
||||
if (size == sizeof(value))
|
||||
goto out;
|
||||
|
||||
/* got a valid value, store and return it */
|
||||
value[size] = '\0';
|
||||
remove_trailing_chars(value, '\n');
|
||||
dbg("cache '%s' with attribute value '%s'", path_full, value);
|
||||
strlcpy(attr->value_local, value, sizeof(attr->value_local));
|
||||
attr->value = attr->value_local;
|
||||
|
||||
out:
|
||||
return attr->value;
|
||||
}
|
||||
|
15
udevinfo.c
15
udevinfo.c
@ -26,6 +26,8 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "udev.h"
|
||||
|
||||
@ -56,10 +58,23 @@ static void print_all_attributes(const char *devpath, const char *key)
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user