1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #if 0 /// elogind needs the systems udev header
12 #include "alloc-util.h"
13 #include "locale-util.h"
14 #include "path-util.h"
15 #include "string-util.h"
16 #include "sysfs-show.h"
17 #include "terminal-util.h"
18 #include "udev-util.h"
21 static int show_sysfs_one(
24 struct udev_list_entry **item,
37 if (flags & OUTPUT_FULL_WIDTH)
38 max_width = (size_t) -1;
39 else if (n_columns < 10)
42 max_width = n_columns;
45 _cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
46 struct udev_list_entry *next, *lookahead;
47 const char *sn, *name, *sysfs, *subsystem, *sysname;
48 _cleanup_free_ char *k = NULL, *l = NULL;
51 sysfs = udev_list_entry_get_name(*item);
52 if (!path_startswith(sysfs, sub))
55 d = udev_device_new_from_syspath(udev, sysfs);
57 *item = udev_list_entry_get_next(*item);
61 sn = udev_device_get_property_value(d, "ID_SEAT");
65 /* Explicitly also check for tag 'seat' here */
66 if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) {
67 *item = udev_list_entry_get_next(*item);
71 is_master = udev_device_has_tag(d, "master-of-seat");
73 name = udev_device_get_sysattr_value(d, "name");
75 name = udev_device_get_sysattr_value(d, "id");
76 subsystem = udev_device_get_subsystem(d);
77 sysname = udev_device_get_sysname(d);
79 /* Look if there's more coming after this */
80 lookahead = next = udev_list_entry_get_next(*item);
82 const char *lookahead_sysfs;
84 lookahead_sysfs = udev_list_entry_get_name(lookahead);
86 if (path_startswith(lookahead_sysfs, sub) &&
87 !path_startswith(lookahead_sysfs, sysfs)) {
88 _cleanup_(udev_device_unrefp) struct udev_device *lookahead_d = NULL;
90 lookahead_d = udev_device_new_from_syspath(udev, lookahead_sysfs);
92 const char *lookahead_sn;
94 lookahead_sn = udev_device_get_property_value(d, "ID_SEAT");
95 if (isempty(lookahead_sn))
96 lookahead_sn = "seat0";
98 if (streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat"))
103 lookahead = udev_list_entry_get_next(lookahead);
106 k = ellipsize(sysfs, max_width, 20);
110 printf("%s%s%s\n", prefix, special_glyph(lookahead ? TREE_BRANCH : TREE_RIGHT), k);
114 is_master ? "[MASTER] " : "",
116 name ? " \"" : "", strempty(name), name ? "\"" : "") < 0)
120 k = ellipsize(l, max_width, 70);
124 printf("%s%s%s\n", prefix, lookahead ? special_glyph(TREE_VERTICAL) : " ", k);
128 _cleanup_free_ char *p = NULL;
130 p = strappend(prefix, lookahead ? special_glyph(TREE_VERTICAL) : " ");
134 show_sysfs_one(udev, seat, item, sysfs, p,
135 n_columns == (unsigned) -1 || n_columns < 2 ? n_columns : n_columns - 2,
143 int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputFlags flags) {
144 _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL;
145 _cleanup_(udev_unrefp) struct udev *udev = NULL;
146 struct udev_list_entry *first = NULL;
150 n_columns = columns();
152 prefix = strempty(prefix);
161 e = udev_enumerate_new(udev);
165 if (!streq(seat, "seat0"))
166 r = udev_enumerate_add_match_tag(e, seat);
168 r = udev_enumerate_add_match_tag(e, "seat");
172 r = udev_enumerate_add_match_is_initialized(e);
176 r = udev_enumerate_scan_devices(e);
180 first = udev_enumerate_get_list_entry(e);
182 show_sysfs_one(udev, seat, &first, "/", prefix, n_columns, flags);
184 printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)");