[systemd-devel] [PATCH] systemctl: show hint about --full when lines don't fit

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Aug 3 16:45:55 PDT 2013


Looks like:

$ systemctl status avahi-daemon
avahi-daemon.service - Avahi mDNS/DNS-SD Stack
   Loaded: loaded (/usr/lib/systemd/system/avahi-daemon.service; enabled)
   Active: active (running) since Tue 2013-07-30 08:15:45 EDT; 4 days ago
 Main PID: 679 (avahi-daemon)
   Status: "Server startup complete. Host name is spora.local. Local service cookie is 4134796673."
   CGroup: /system/avahi-daemon.service
           ├─679 avahi-daemon: running [spora.local]
           └─758 avahi-daemon: chroot helper

Aug 03 11:00:55 spora avahi-daemon[679]: Registering new address record for 10.0.66.2 on ...v4.
Aug 03 12:35:27 spora avahi-daemon[679]: Interface bnep0.IPv4 no longer relevant for mDNS.
-- some lines were ellipsized, use -l to show in full

The hint is only printed once, at the end, if the status for more
than one unit is printed.
---
Would something like that be useful for setroubleshoot output?

Zbyszek

 src/journal/journal-gatewayd.c |  2 +-
 src/journal/journalctl.c       |  3 ++-
 src/shared/logs-show.c         | 37 ++++++++++++++++++++++------------
 src/shared/logs-show.h         |  6 ++++--
 src/systemctl/systemctl.c      | 45 ++++++++++++++++++++++++++++++------------
 5 files changed, 63 insertions(+), 30 deletions(-)

diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index 10224a1..06a236d 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -248,7 +248,7 @@ static ssize_t request_reader_entries(
                         }
                 }
 
-                r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH);
+                r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH, NULL);
                 if (r < 0) {
                         log_error("Failed to serialize item: %s", strerror(-r));
                         return MHD_CONTENT_READER_END_WITH_ERROR;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index dde2ed7..ee84691 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1305,6 +1305,7 @@ int main(int argc, char *argv[]) {
         sd_id128_t previous_boot_id;
         bool previous_boot_id_valid = false, first_line = true;
         int n_shown = 0;
+        bool ellipsized = false;
 
         setlocale(LC_ALL, "");
         log_parse_environment();
@@ -1625,7 +1626,7 @@ int main(int argc, char *argv[]) {
                                 on_tty() * OUTPUT_COLOR |
                                 arg_catalog * OUTPUT_CATALOG;
 
-                        r = output_journal(stdout, j, arg_output, 0, flags);
+                        r = output_journal(stdout, j, arg_output, 0, flags, &ellipsized);
                         need_seek = true;
                         if (r == -EADDRNOTAVAIL)
                                 break;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index bd7363a..51cd7d5 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -101,10 +101,11 @@ static bool shall_print(const char *p, size_t l, OutputFlags flags) {
         return true;
 }
 
-static void print_multiline(FILE *f, unsigned prefix, unsigned n_columns, OutputMode flags, int priority, const char* message, size_t message_len) {
+static bool print_multiline(FILE *f, unsigned prefix, unsigned n_columns, OutputMode flags, int priority, const char* message, size_t message_len) {
         const char *color_on = "", *color_off = "";
         const char *pos, *end;
         bool continuation = false;
+        bool ellipsized = false;
 
         if (flags & OUTPUT_COLOR) {
                 if (priority <= LOG_ERR) {
@@ -130,17 +131,22 @@ static void print_multiline(FILE *f, unsigned prefix, unsigned n_columns, Output
                 else if (prefix < n_columns && n_columns - prefix >= 3) {
                         _cleanup_free_ char *e;
 
+                        ellipsized = true;
                         e = ellipsize_mem(pos, len, n_columns - prefix, 90);
 
                         if (!e)
                                 fprintf(f, "%s%.*s%s\n", color_on, len, pos, color_off);
                         else
                                 fprintf(f, "%s%s%s\n", color_on, e, color_off);
-                } else
+                } else {
+                        ellipsized = true;
                         fputs("...\n", f);
+                }
 
                 continuation = true;
         }
+
+        return ellipsized;
 }
 
 static int output_short(
@@ -157,6 +163,7 @@ static int output_short(
         _cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL;
         size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0;
         int p = LOG_INFO;
+        bool ellipsized = false;
 
         assert(f);
         assert(j);
@@ -314,13 +321,14 @@ static int output_short(
                 fprintf(f, ": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
         } else {
                 fputs(": ", f);
-                print_multiline(f, n + 2, n_columns, flags, p, message, message_len);
+                ellipsized |=
+                        print_multiline(f, n + 2, n_columns, flags, p, message, message_len);
         }
 
         if (flags & OUTPUT_CATALOG)
                 print_catalog(f, j);
 
-        return 0;
+        return ellipsized;
 }
 
 static int output_verbose(
@@ -817,7 +825,8 @@ int output_journal(
                 sd_journal *j,
                 OutputMode mode,
                 unsigned n_columns,
-                OutputFlags flags) {
+                OutputFlags flags,
+                bool *ellipsized) {
 
         int ret;
         assert(mode >= 0);
@@ -828,6 +837,10 @@ int output_journal(
 
         ret = output_funcs[mode](f, j, mode, n_columns, flags);
         fflush(stdout);
+
+        if (ellipsized && ret > 0)
+                *ellipsized = true;
+
         return ret;
 }
 
@@ -837,7 +850,8 @@ static int show_journal(FILE *f,
                         unsigned n_columns,
                         usec_t not_before,
                         unsigned how_many,
-                        OutputFlags flags) {
+                        OutputFlags flags,
+                        bool *ellipsized) {
 
         int r;
         unsigned line = 0;
@@ -888,7 +902,7 @@ static int show_journal(FILE *f,
 
                         line ++;
 
-                        r = output_journal(f, j, mode, n_columns, flags);
+                        r = output_journal(f, j, mode, n_columns, flags, ellipsized);
                         if (r < 0)
                                 goto finish;
                 }
@@ -1037,7 +1051,8 @@ int show_journal_by_unit(
                 unsigned how_many,
                 uid_t uid,
                 OutputFlags flags,
-                bool system) {
+                bool system,
+                bool *ellipsized) {
 
         _cleanup_journal_close_ sd_journal*j = NULL;
         int r;
@@ -1072,11 +1087,7 @@ int show_journal_by_unit(
                 log_debug("Journal filter: %s", filter);
         }
 
-        r = show_journal(f, j, mode, n_columns, not_before, how_many, flags);
-        if (r < 0)
-                return r;
-
-        return 0;
+        return show_journal(f, j, mode, n_columns, not_before, how_many, flags, ellipsized);
 }
 
 static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h
index c9a9ad3..11b3b59 100644
--- a/src/shared/logs-show.h
+++ b/src/shared/logs-show.h
@@ -35,7 +35,8 @@ int output_journal(
                 sd_journal *j,
                 OutputMode mode,
                 unsigned n_columns,
-                OutputFlags flags);
+                OutputFlags flags,
+                bool *ellipsized);
 
 int add_match_this_boot(sd_journal *j);
 
@@ -57,7 +58,8 @@ int show_journal_by_unit(
                 unsigned how_many,
                 uid_t uid,
                 OutputFlags flags,
-                bool system);
+                bool system,
+                bool *ellipsized);
 
 void json_escape(
                 FILE *f,
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5a4d80c..e859c07 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2527,7 +2527,8 @@ typedef struct UnitStatusInfo {
         LIST_HEAD(ExecStatusInfo, exec);
 } UnitStatusInfo;
 
-static void print_status_info(UnitStatusInfo *i) {
+static void print_status_info(UnitStatusInfo *i,
+                              bool *ellipsized) {
         ExecStatusInfo *p;
         const char *on, *off, *ss;
         usec_t timestamp;
@@ -2803,7 +2804,8 @@ static void print_status_info(UnitStatusInfo *i) {
                                      arg_lines,
                                      getuid(),
                                      flags,
-                                     arg_scope == UNIT_FILE_SYSTEM);
+                                     arg_scope == UNIT_FILE_SYSTEM,
+                                     ellipsized);
         }
 
         if (i->need_daemon_reload)
@@ -3369,7 +3371,12 @@ static int print_property(const char *name, DBusMessageIter *iter) {
         return 0;
 }
 
-static int show_one(const char *verb, DBusConnection *bus, const char *path, bool show_properties, bool *new_line) {
+static int show_one(const char *verb,
+                    DBusConnection *bus,
+                    const char *path,
+                    bool show_properties,
+                    bool *new_line,
+                    bool *ellipsized) {
         _cleanup_free_ DBusMessage *reply = NULL;
         const char *interface = "";
         int r;
@@ -3439,7 +3446,7 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
                 if (streq(verb, "help"))
                         show_unit_help(&info);
                 else
-                        print_status_info(&info);
+                        print_status_info(&info, ellipsized);
         }
 
         strv_free(info.documentation);
@@ -3470,7 +3477,11 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
         return r;
 }
 
-static int show_one_by_pid(const char *verb, DBusConnection *bus, uint32_t pid, bool *new_line) {
+static int show_one_by_pid(const char *verb,
+                           DBusConnection *bus,
+                           uint32_t pid,
+                           bool *new_line,
+                           bool *ellipsized) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         const char *path = NULL;
         _cleanup_dbus_error_free_ DBusError error;
@@ -3498,11 +3509,15 @@ static int show_one_by_pid(const char *verb, DBusConnection *bus, uint32_t pid,
                 return -EIO;
         }
 
-        r = show_one(verb, bus, path, false, new_line);
+        r = show_one(verb, bus, path, false, new_line, ellipsized);
         return r;
 }
 
-static int show_all(const char* verb, DBusConnection *bus, bool show_properties, bool *new_line) {
+static int show_all(const char* verb,
+                    DBusConnection *bus,
+                    bool show_properties,
+                    bool *new_line,
+                    bool *ellipsized) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         _cleanup_free_ struct unit_info *unit_infos = NULL;
         unsigned c = 0;
@@ -3527,7 +3542,7 @@ static int show_all(const char* verb, DBusConnection *bus, bool show_properties,
 
                 printf("%s -> '%s'\n", u->id, p);
 
-                r = show_one(verb, bus, p, show_properties, new_line);
+                r = show_one(verb, bus, p, show_properties, new_line, ellipsized);
                 if (r != 0)
                         return r;
         }
@@ -3539,6 +3554,7 @@ static int show(DBusConnection *bus, char **args) {
         int r, ret = 0;
         bool show_properties, show_status, new_line = false;
         char **name;
+        bool ellipsized = false;
 
         assert(bus);
         assert(args);
@@ -3552,10 +3568,10 @@ static int show(DBusConnection *bus, char **args) {
         /* If no argument is specified inspect the manager itself */
 
         if (show_properties && strv_length(args) <= 1)
-                return show_one(args[0], bus, "/org/freedesktop/systemd1", show_properties, &new_line);
+                return show_one(args[0], bus, "/org/freedesktop/systemd1", show_properties, &new_line, &ellipsized);
 
         if (show_status && strv_length(args) <= 1)
-                return show_all(args[0], bus, false, &new_line);
+                return show_all(args[0], bus, false, &new_line, &ellipsized);
 
         STRV_FOREACH(name, args+1) {
                 uint32_t id;
@@ -3572,7 +3588,7 @@ static int show(DBusConnection *bus, char **args) {
                         if (!p)
                                 return log_oom();
 
-                        r = show_one(args[0], bus, p, show_properties, &new_line);
+                        r = show_one(args[0], bus, p, show_properties, &new_line, &ellipsized);
                         if (r != 0)
                                 ret = r;
 
@@ -3583,18 +3599,21 @@ static int show(DBusConnection *bus, char **args) {
                         if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0)
                                 return log_oom();
 
-                        r = show_one(args[0], bus, p, show_properties, &new_line);
+                        r = show_one(args[0], bus, p, show_properties, &new_line, &ellipsized);
                         if (r != 0)
                                 ret = r;
 
                 } else {
                         /* Interpret as PID */
-                        r = show_one_by_pid(args[0], bus, id, &new_line);
+                        r = show_one_by_pid(args[0], bus, id, &new_line, &ellipsized);
                         if (r != 0)
                                 ret = r;
                 }
         }
 
+        if (ellipsized && !arg_quiet)
+                printf("-- some lines were ellipsized, use -l to show in full\n");
+
         return ret;
 }
 
-- 
1.8.2.562.g931e949



More information about the systemd-devel mailing list