]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loginctl: rework sysfs tree dump, to honour --full and friends 7301/head
authorLennart Poettering <lennart@poettering.net>
Fri, 10 Nov 2017 20:44:29 +0000 (21:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Nov 2017 20:44:29 +0000 (21:44 +0100)
Let's hook up the sysfs tree output with the output flags logic,
already used when dumping log lines or process trees. This way we get
very similar output handling for line breaking/ellipsation in all three
outputs of structured data.

Fixes: #7095
src/login/loginctl.c
src/login/sysfs-show.c
src/login/sysfs-show.h

index c849db7b086de3de5f555c8bd969f2b9af196a27..49624ba7d06bac30cb17c7b9345d425a85d157f8 100644 (file)
@@ -714,7 +714,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line)
 
                 printf("\t Devices:\n");
 
-                show_sysfs(i.id, "\t\t  ", c);
+                show_sysfs(i.id, "\t\t  ", c, get_output_flags());
         }
 
         return 0;
index 29785e2f11d5f55c2256997aa391166ed31f297e..bf6feaa0d9b8281bab55d6484a712e07aa53e48c 100644 (file)
@@ -37,13 +37,23 @@ static int show_sysfs_one(
                 struct udev_list_entry **item,
                 const char *sub,
                 const char *prefix,
-                unsigned n_columns) {
+                unsigned n_columns,
+                OutputFlags flags) {
+
+        size_t max_width;
 
         assert(udev);
         assert(seat);
         assert(item);
         assert(prefix);
 
+        if (flags & OUTPUT_FULL_WIDTH)
+                max_width = (size_t) -1;
+        else if (n_columns < 10)
+                max_width = 10;
+        else
+                max_width = n_columns;
+
         while (*item) {
                 _cleanup_udev_device_unref_ struct udev_device *d = NULL;
                 struct udev_list_entry *next, *lookahead;
@@ -106,7 +116,7 @@ static int show_sysfs_one(
                         lookahead = udev_list_entry_get_next(lookahead);
                 }
 
-                k = ellipsize(sysfs, n_columns, 20);
+                k = ellipsize(sysfs, max_width, 20);
                 if (!k)
                         return -ENOMEM;
 
@@ -120,7 +130,7 @@ static int show_sysfs_one(
                         return -ENOMEM;
 
                 free(k);
-                k = ellipsize(l, n_columns, 70);
+                k = ellipsize(l, max_width, 70);
                 if (!k)
                         return -ENOMEM;
 
@@ -134,14 +144,16 @@ static int show_sysfs_one(
                         if (!p)
                                 return -ENOMEM;
 
-                        show_sysfs_one(udev, seat, item, sysfs, p, n_columns - 2);
+                        show_sysfs_one(udev, seat, item, sysfs, p,
+                                       n_columns == (unsigned) -1 || n_columns < 2 ? n_columns : n_columns - 2,
+                                       flags);
                 }
         }
 
         return 0;
 }
 
-int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
+int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputFlags flags) {
         _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
         _cleanup_udev_unref_ struct udev *udev = NULL;
         struct udev_list_entry *first = NULL;
@@ -150,8 +162,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
         if (n_columns <= 0)
                 n_columns = columns();
 
-        if (!prefix)
-                prefix = "";
+        prefix = strempty(prefix);
 
         if (isempty(seat))
                 seat = "seat0";
@@ -181,7 +192,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
 
         first = udev_enumerate_get_list_entry(e);
         if (first)
-                show_sysfs_one(udev, seat, &first, "/", prefix, n_columns);
+                show_sysfs_one(udev, seat, &first, "/", prefix, n_columns, flags);
         else
                 printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)");
 
index 3e94bc3ed55a78a0245a925b7e381f3f99671117..e19af4cd928db77b7d6a0decaeaf320a7ae561ab 100644 (file)
@@ -19,4 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-int show_sysfs(const char *seat, const char *prefix, unsigned columns);
+#include <sys/types.h>
+
+#include "output-mode.h"
+
+int show_sysfs(const char *seat, const char *prefix, unsigned columns, OutputFlags flags);