summaryrefslogtreecommitdiff
path: root/test/get_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/get_device.c')
-rw-r--r--test/get_device.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/test/get_device.c b/test/get_device.c
index 7e20608..9d13d9f 100644
--- a/test/get_device.c
+++ b/test/get_device.c
@@ -27,42 +27,36 @@
void print_usage(void)
{
- fprintf(stdout, "Usage: get_device [device]\n");
+ fprintf(stdout, "Usage: get_device [bus] [device]\n");
}
int main(int argc, char *argv[])
{
- char *bus = NULL;
struct sysfs_device *device = NULL;
struct sysfs_attribute *attr = NULL;
+ struct dlist *attrlist = NULL;
- if (argc != 2) {
+ if (argc != 3) {
print_usage();
return 1;
}
- bus = (char *)calloc(1, SYSFS_NAME_LEN);
- if ((sysfs_find_device_bus(argv[1], bus, SYSFS_NAME_LEN)) < 0) {
- fprintf(stdout, "Device %s not found\n", argv[1]);
- free (bus);
- return 1;
- }
- fprintf(stdout, "Device %s is a member of bus %s\n",
- argv[1], bus);
- device = sysfs_open_device_by_id(argv[1], bus, SYSFS_NAME_LEN);
+ device = sysfs_open_device_by_id(argv[2], argv[1], strlen(argv[1]));
if (device == NULL) {
- fprintf(stdout, "Device %s not found\n", argv[1]);
- free(bus);
+ fprintf(stdout, "Device %s not found on bus %s\n",
+ argv[2], argv[1]);
return 1;
}
- dlist_for_each_data(device->directory->attributes, attr,
- struct sysfs_attribute) {
- fprintf(stdout, "\t%s : %s", attr->name, attr->value);
+
+ attrlist = sysfs_get_device_attributes(device);
+ if (attrlist != NULL) {
+ dlist_for_each_data(attrlist, attr,
+ struct sysfs_attribute)
+ fprintf(stdout, "\t%s : %s", attr->name, attr->value);
}
fprintf(stdout, "\n");
sysfs_close_device(device);
- free(bus);
return 0;
}