X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Fsysfs-show.c;h=f7d11ddc4cdc528d39619b4132fab76bf315b4b1;hb=5f7e8903b275f14d0f41f0542871d09deccb1741;hp=172c75d82b0fc4c3a5215eadfd6be2e5a720a1cf;hpb=c339d9775d1df19fdbbafc57486f7cd51af6b7fb;p=elogind.git diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index 172c75d82..f7d11ddc4 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -26,6 +26,7 @@ #include "util.h" #include "sysfs-show.h" #include "path-util.h" +#include "udev-util.h" static int show_sysfs_one( struct udev *udev, @@ -45,6 +46,7 @@ static int show_sysfs_one( struct udev_device *d; const char *sn, *name, *sysfs, *subsystem, *sysname; char *l, *k; + bool is_master; sysfs = udev_list_entry_get_name(*item); if (!path_startswith(sysfs, sub)) @@ -60,13 +62,15 @@ static int show_sysfs_one( if (isempty(sn)) sn = "seat0"; - /* fixme, also check for tag 'seat' here */ + /* Explicitly also check for tag 'seat' here */ if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) { udev_device_unref(d); *item = udev_list_entry_get_next(*item); continue; } + is_master = udev_device_has_tag(d, "master-of-seat"); + name = udev_device_get_sysattr_value(d, "name"); if (!name) name = udev_device_get_sysattr_value(d, "id"); @@ -105,12 +109,13 @@ static int show_sysfs_one( } k = ellipsize(sysfs, n_columns, 20); - printf("%s%s %s\n", prefix, draw_special_char(lookahead ? DRAW_BOX_VERT_AND_RIGHT : DRAW_BOX_UP_AND_RIGHT), - k ? k : sysfs); + printf("%s%s%s\n", prefix, draw_special_char(lookahead ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT), + k ? k : sysfs); free(k); if (asprintf(&l, - "(%s:%s)%s%s%s", + "%s%s:%s%s%s%s", + is_master ? "[MASTER] " : "", subsystem, sysname, name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) { udev_device_unref(d); @@ -118,8 +123,8 @@ static int show_sysfs_one( } k = ellipsize(l, n_columns, 70); - printf("%s%s %s\n", prefix, lookahead ? draw_special_char(DRAW_BOX_VERT) : " ", - k ? k : l); + printf("%s%s%s\n", prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : " ", + k ? k : l); free(k); free(l); @@ -127,7 +132,7 @@ static int show_sysfs_one( if (*item) { char *p; - p = strjoin(prefix, lookahead ? draw_special_char(DRAW_BOX_VERT) : " ", " ", NULL); + p = strappend(prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : " "); show_sysfs_one(udev, seat, item, sysfs, p ? p : prefix, n_columns - 2); free(p); } @@ -139,9 +144,9 @@ static int show_sysfs_one( } int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { - struct udev *udev; + _cleanup_udev_unref_ struct udev *udev; + _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL; struct udev_list_entry *first = NULL; - struct udev_enumerate *e; int r; if (n_columns <= 0) @@ -158,10 +163,8 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { return -ENOMEM; e = udev_enumerate_new(udev); - if (!e) { - r = -ENOMEM; - goto finish; - } + if (!e) + return -ENOMEM; if (!streq(seat, "seat0")) r = udev_enumerate_add_match_tag(e, seat); @@ -169,22 +172,15 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { r = udev_enumerate_add_match_tag(e, "seat"); if (r < 0) - goto finish; + return r; r = udev_enumerate_scan_devices(e); if (r < 0) - goto finish; + return r; first = udev_enumerate_get_list_entry(e); if (first) show_sysfs_one(udev, seat, &first, "/", prefix, n_columns); -finish: - if (e) - udev_enumerate_unref(e); - - if (udev) - udev_unref(udev); - return r; }