1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
11 #if 0 /// elogind needs the systems udev header
17 #include "alloc-util.h"
18 #include "locale-util.h"
19 #include "path-util.h"
20 #include "string-util.h"
21 #include "sysfs-show.h"
22 #include "terminal-util.h"
23 #include "udev-util.h"
26 static int show_sysfs_one(
29 struct udev_list_entry **item,
42 if (flags & OUTPUT_FULL_WIDTH)
43 max_width = (size_t) -1;
44 else if (n_columns < 10)
47 max_width = n_columns;
50 _cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
51 struct udev_list_entry *next, *lookahead;
52 const char *sn, *name, *sysfs, *subsystem, *sysname;
53 _cleanup_free_ char *k = NULL, *l = NULL;
56 sysfs = udev_list_entry_get_name(*item);
57 if (!path_startswith(sysfs, sub))
60 d = udev_device_new_from_syspath(udev, sysfs);
62 *item = udev_list_entry_get_next(*item);
66 sn = udev_device_get_property_value(d, "ID_SEAT");
70 /* Explicitly also check for tag 'seat' here */
71 if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) {
72 *item = udev_list_entry_get_next(*item);
76 is_master = udev_device_has_tag(d, "master-of-seat");
78 name = udev_device_get_sysattr_value(d, "name");
80 name = udev_device_get_sysattr_value(d, "id");
81 subsystem = udev_device_get_subsystem(d);
82 sysname = udev_device_get_sysname(d);
84 /* Look if there's more coming after this */
85 lookahead = next = udev_list_entry_get_next(*item);
87 const char *lookahead_sysfs;
89 lookahead_sysfs = udev_list_entry_get_name(lookahead);
91 if (path_startswith(lookahead_sysfs, sub) &&
92 !path_startswith(lookahead_sysfs, sysfs)) {
93 _cleanup_(udev_device_unrefp) struct udev_device *lookahead_d = NULL;
95 lookahead_d = udev_device_new_from_syspath(udev, lookahead_sysfs);
97 const char *lookahead_sn;
99 lookahead_sn = udev_device_get_property_value(d, "ID_SEAT");
100 if (isempty(lookahead_sn))
101 lookahead_sn = "seat0";
103 if (streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat"))
108 lookahead = udev_list_entry_get_next(lookahead);
111 k = ellipsize(sysfs, max_width, 20);
115 printf("%s%s%s\n", prefix, special_glyph(lookahead ? TREE_BRANCH : TREE_RIGHT), k);
119 is_master ? "[MASTER] " : "",
121 name ? " \"" : "", strempty(name), name ? "\"" : "") < 0)
125 k = ellipsize(l, max_width, 70);
129 printf("%s%s%s\n", prefix, lookahead ? special_glyph(TREE_VERTICAL) : " ", k);
133 _cleanup_free_ char *p = NULL;
135 p = strappend(prefix, lookahead ? special_glyph(TREE_VERTICAL) : " ");
139 show_sysfs_one(udev, seat, item, sysfs, p,
140 n_columns == (unsigned) -1 || n_columns < 2 ? n_columns : n_columns - 2,
148 int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputFlags flags) {
149 _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL;
150 _cleanup_(udev_unrefp) struct udev *udev = NULL;
151 struct udev_list_entry *first = NULL;
155 n_columns = columns();
157 prefix = strempty(prefix);
166 e = udev_enumerate_new(udev);
170 if (!streq(seat, "seat0"))
171 r = udev_enumerate_add_match_tag(e, seat);
173 r = udev_enumerate_add_match_tag(e, "seat");
177 r = udev_enumerate_add_match_is_initialized(e);
181 r = udev_enumerate_scan_devices(e);
185 first = udev_enumerate_get_list_entry(e);
187 show_sysfs_one(udev, seat, &first, "/", prefix, n_columns, flags);
189 printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)");