1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include "sysfs-show.h"
28 #include "path-util.h"
30 static int show_sysfs_one(
33 struct udev_list_entry **item,
44 struct udev_list_entry *next, *lookahead;
45 struct udev_device *d;
46 const char *sn, *name, *sysfs, *subsystem, *sysname;
49 sysfs = udev_list_entry_get_name(*item);
50 if (!path_startswith(sysfs, sub))
53 d = udev_device_new_from_syspath(udev, sysfs);
55 *item = udev_list_entry_get_next(*item);
59 sn = udev_device_get_property_value(d, "ID_SEAT");
63 /* fixme, also check for tag 'seat' here */
64 if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) {
66 *item = udev_list_entry_get_next(*item);
70 name = udev_device_get_sysattr_value(d, "name");
72 name = udev_device_get_sysattr_value(d, "id");
73 subsystem = udev_device_get_subsystem(d);
74 sysname = udev_device_get_sysname(d);
76 /* Look if there's more coming after this */
77 lookahead = next = udev_list_entry_get_next(*item);
79 const char *lookahead_sysfs;
81 lookahead_sysfs = udev_list_entry_get_name(lookahead);
83 if (path_startswith(lookahead_sysfs, sub) &&
84 !path_startswith(lookahead_sysfs, sysfs)) {
85 struct udev_device *lookahead_d;
87 lookahead_d = udev_device_new_from_syspath(udev, lookahead_sysfs);
89 const char *lookahead_sn;
92 lookahead_sn = udev_device_get_property_value(d, "ID_SEAT");
93 if (isempty(lookahead_sn))
94 lookahead_sn = "seat0";
96 found = streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat");
97 udev_device_unref(lookahead_d);
104 lookahead = udev_list_entry_get_next(lookahead);
107 k = ellipsize(sysfs, n_columns, 20);
108 printf("%s%s %s\n", prefix, draw_special_char(lookahead ? DRAW_BOX_VERT_AND_RIGHT : DRAW_BOX_UP_AND_RIGHT),
115 name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) {
116 udev_device_unref(d);
120 k = ellipsize(l, n_columns, 70);
121 printf("%s%s %s\n", prefix, lookahead ? draw_special_char(DRAW_BOX_VERT) : " ",
130 p = strjoin(prefix, lookahead ? draw_special_char(DRAW_BOX_VERT) : " ", " ", NULL);
131 show_sysfs_one(udev, seat, item, sysfs, p ? p : prefix, n_columns - 2);
135 udev_device_unref(d);
141 int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
143 struct udev_list_entry *first = NULL;
144 struct udev_enumerate *e;
148 n_columns = columns();
160 e = udev_enumerate_new(udev);
166 if (!streq(seat, "seat0"))
167 r = udev_enumerate_add_match_tag(e, seat);
169 r = udev_enumerate_add_match_tag(e, "seat");
174 r = udev_enumerate_scan_devices(e);
178 first = udev_enumerate_get_list_entry(e);
180 show_sysfs_one(udev, seat, &first, "/", prefix, n_columns);
184 udev_enumerate_unref(e);