summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-08-28 16:05:20 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-09-10 16:47:35 +0900
commite132a043926c9bea72b41ea1fd921882976ff94f (patch)
tree8334fb6778ada6c634880d5b57b401c2e5cf1d1e /src
parent708474c5a06f590748cf37392b9eef803740719b (diff)
downloadsystemd-e132a043926c9bea72b41ea1fd921882976ff94f.tar.gz
login/sysfs-show: use device_enumerator_get_devices()
Diffstat (limited to 'src')
-rw-r--r--src/login/sysfs-show.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c
index 5d2a6ad209..758f9c2c1d 100644
--- a/src/login/sysfs-show.c
+++ b/src/login/sysfs-show.c
@@ -127,8 +127,8 @@ static int show_sysfs_one(
int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputFlags flags) {
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
- size_t n_dev = 0, n_allocated = 0, i = 0;
- sd_device *d, **dev_list = NULL;
+ size_t n_dev = 0, i = 0;
+ sd_device **dev_list;
int r;
if (n_columns <= 0)
@@ -155,27 +155,12 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputF
if (r < 0)
return r;
- FOREACH_DEVICE_AND_SUBSYSTEM(e, d) {
- const char *syspath;
+ dev_list = device_enumerator_get_devices(e, &n_dev);
- if (sd_device_get_syspath(d, &syspath) < 0)
- continue;
-
- if (!GREEDY_REALLOC(dev_list, n_allocated, n_dev + 2))
- return -ENOMEM;
-
- dev_list[n_dev++] = sd_device_ref(d);
- dev_list[n_dev] = NULL;
- }
-
- if (n_dev > 0)
+ if (dev_list && n_dev > 0)
show_sysfs_one(seat, dev_list, &i, n_dev, "/", prefix, n_columns, flags);
else
printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)");
- for (i = 0; i < n_dev; i++)
- sd_device_unref(dev_list[i]);
- free(dev_list);
-
return 0;
}