X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsysfs-show.c;h=ab866a470755235aaaec899e1c5e433453fbdff6;hp=d12d3ccfc92b6de0f5a1bc489fa81183ea0e46e4;hb=add30678a1bf284ecd79438d219c45ca7a1c9f51;hpb=24310c11ba1a45530499541f247e52d7fe8952b5 diff --git a/src/sysfs-show.c b/src/sysfs-show.c index d12d3ccfc..ab866a470 100644 --- a/src/sysfs-show.c +++ b/src/sysfs-show.c @@ -26,23 +26,6 @@ #include "util.h" #include "sysfs-show.h" -static bool device_has_tag(struct udev_device *d, const char *tag) { - struct udev_list_entry *first, *item; - - assert(d); - assert(tag); - - /* FIXME */ - udev_device_get_is_initialized(d); - - first = udev_device_get_tags_list_entry(d); - udev_list_entry_foreach(item, first) - if (streq(udev_list_entry_get_name(item), tag)) - return true; - - return false; -} - static int show_sysfs_one( struct udev *udev, const char *seat, @@ -59,7 +42,8 @@ static int show_sysfs_one( while (*item) { struct udev_list_entry *next, *lookahead; struct udev_device *d; - const char *sn, *id, *name, *sysfs, *subsystem, *sysname; + const char *sn, *name, *sysfs, *subsystem, *sysname; + char *l, *k; sysfs = udev_list_entry_get_name(*item); if (!path_startswith(sysfs, sub)) @@ -76,13 +60,12 @@ static int show_sysfs_one( sn = "seat0"; /* fixme, also check for tag 'seat' here */ - if (!streq(seat, sn) || !device_has_tag(d, "seat")) { + if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) { udev_device_unref(d); *item = udev_list_entry_get_next(*item); continue; } - id = udev_device_get_property_value(d, "ID_FOR_SEAT"); name = udev_device_get_sysattr_value(d, "name"); if (!name) name = udev_device_get_sysattr_value(d, "id"); @@ -109,7 +92,7 @@ static int show_sysfs_one( if (isempty(lookahead_sn)) lookahead_sn = "seat0"; - found = streq(seat, lookahead_sn) && device_has_tag(d, "seat"); + found = streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat"); udev_device_unref(lookahead_d); if (found) @@ -120,19 +103,29 @@ static int show_sysfs_one( lookahead = udev_list_entry_get_next(lookahead); } - printf("%s%s %s (%s:%s)", prefix, lookahead ? "\342\224\234" : "\342\224\224", id ? id : sysfs, subsystem, sysname); + k = ellipsize(sysfs, n_columns, 20); + printf("%s%s %s\n", prefix, lookahead ? "\342\224\234" : "\342\224\224", k ? k : sysfs); + free(k); + + if (asprintf(&l, + "(%s:%s)%s%s%s", + subsystem, sysname, + name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) { + udev_device_unref(d); + return -ENOMEM; + } - if (name) - printf(" \"%s\"\n", name); - else - printf("\n"); + k = ellipsize(l, n_columns, 70); + printf("%s%s %s\n", prefix, lookahead ? "\342\224\202" : " ", k ? k : l); + free(k); + free(l); *item = next; if (*item) { char *p; p = strappend(prefix, lookahead ? "\342\224\202 " : " "); - show_sysfs_one(udev, seat, item, sysfs, p, n_columns - 2); + show_sysfs_one(udev, seat, item, sysfs, p ? p : prefix, n_columns - 2); free(p); }