[systemd-commits] 3 commits - src/journal src/shared src/systemctl

Lennart Poettering lennart at kemper.freedesktop.org
Tue Jul 17 08:21:17 PDT 2012


 src/journal/journalctl.c  |    8 ++++-
 src/shared/logs-show.c    |   65 +++++++++++++++++++++++++++-------------------
 src/shared/logs-show.h    |   15 +++++++---
 src/systemctl/systemctl.c |    7 ++++
 4 files changed, 62 insertions(+), 33 deletions(-)

New commits:
commit 92a1fd9e95954a557d6fe27b56f5ef1b89fc2f5e
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Jul 17 07:35:08 2012 +0200

    journalctl: do not ellipsize when using pager
    
    If a pager is used, ellipsization is redundant — the pager does
    that better by hiding the part that cannot be shown. Pager's advantage
    is that the user can press → to view the hidden part of a message,
    and then ← to return.

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 016750c..e9810c9 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -312,6 +312,7 @@ int main(int argc, char *argv[]) {
         bool need_seek = false;
         sd_id128_t previous_boot_id;
         bool previous_boot_id_valid = false;
+        bool have_pager;
 
         log_parse_environment();
         log_open();
@@ -397,7 +398,8 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if (!arg_no_pager && !arg_follow) {
+        have_pager = !arg_no_pager && !arg_follow;
+        if (have_pager) {
                 columns();
                 pager_open();
         }
@@ -410,6 +412,8 @@ int main(int argc, char *argv[]) {
         for (;;) {
                 for (;;) {
                         sd_id128_t boot_id;
+                        int flags = (arg_show_all*OUTPUT_SHOW_ALL |
+                                     have_pager*OUTPUT_FULL_WIDTH);
 
                         if (need_seek) {
                                 r = sd_journal_next(j);
@@ -434,8 +438,7 @@ int main(int argc, char *argv[]) {
 
                         line ++;
 
-                        r = output_journal(j, arg_output, line, 0,
-                                           arg_show_all ? OUTPUT_SHOW_ALL : 0);
+                        r = output_journal(j, arg_output, line, 0, flags);
                         if (r < 0)
                                 goto finish;
 
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index bbfb74c..43e42f7 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -225,7 +225,8 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns,
         else if (!utf8_is_printable_n(message, message_len)) {
                 char bytes[FORMAT_BYTES_MAX];
                 printf(": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
-        } else if (message_len + n < n_columns)
+        } else if ((flags & OUTPUT_FULL_WIDTH) ||
+                   (message_len + n < n_columns))
                 printf(": %.*s\n", (int) message_len, message);
         else if (n < n_columns) {
                 char *e;
diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h
index 44afaf3..2e9cf63 100644
--- a/src/shared/logs-show.h
+++ b/src/shared/logs-show.h
@@ -44,6 +44,7 @@ typedef enum OutputFlags {
         OUTPUT_MONOTONIC_MODE = 1 << 1,
         OUTPUT_FOLLOW = 1 << 2,
         OUTPUT_WARN_CUTOFF = 1 << 3,
+        OUTPUT_FULL_WIDTH = 1 << 4,
 } OutputFlags;
 
 int output_journal(sd_journal *j, OutputMode mode, unsigned line,

commit 085d71209ba32c1e4e72ec031536be892054352e
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Jul 17 07:35:07 2012 +0200

    logs: Adapt interface in log-show.c (show_journal_by_unit)
    
    Convert more flag arguments into one flag variable.

diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index af9bcbd..bbfb74c 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -553,15 +553,14 @@ int show_journal_by_unit(
                 unsigned n_columns,
                 usec_t not_before,
                 unsigned how_many,
-                bool show_all,
-                bool follow,
-                bool warn_cutoff) {
+                OutputFlags flags) {
 
         char *m = NULL;
         sd_journal *j = NULL;
         int r;
         unsigned line = 0;
         bool need_seek = false;
+        int warn_cutoff = flags & OUTPUT_WARN_CUTOFF;
 
         assert(mode >= 0);
         assert(mode < _OUTPUT_MODE_MAX);
@@ -633,8 +632,7 @@ int show_journal_by_unit(
 
                         line ++;
 
-                        r = output_journal(j, mode, line, n_columns,
-                                           show_all ? OUTPUT_SHOW_ALL : 0);
+                        r = output_journal(j, mode, line, n_columns, flags);
                         if (r < 0)
                                 goto finish;
                 }
@@ -659,7 +657,7 @@ int show_journal_by_unit(
                         warn_cutoff = false;
                 }
 
-                if (!follow)
+                if (!(flags & OUTPUT_FOLLOW))
                         break;
 
                 r = sd_journal_wait(j, (usec_t) -1);
diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h
index beade06..44afaf3 100644
--- a/src/shared/logs-show.h
+++ b/src/shared/logs-show.h
@@ -42,6 +42,8 @@ typedef enum OutputMode {
 typedef enum OutputFlags {
         OUTPUT_SHOW_ALL = 1 << 0,
         OUTPUT_MONOTONIC_MODE = 1 << 1,
+        OUTPUT_FOLLOW = 1 << 2,
+        OUTPUT_WARN_CUTOFF = 1 << 3,
 } OutputFlags;
 
 int output_journal(sd_journal *j, OutputMode mode, unsigned line,
@@ -53,9 +55,7 @@ int show_journal_by_unit(
                 unsigned n_columns,
                 usec_t not_before,
                 unsigned how_many,
-                bool show_all,
-                bool follow,
-                bool warn_cutoff);
+                OutputFlags flags);
 
 const char* output_mode_to_string(OutputMode m);
 OutputMode output_mode_from_string(const char *s);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 6ab92ce..344dcd3 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2592,8 +2592,13 @@ static void print_status_info(UnitStatusInfo *i) {
         }
 
         if (i->id && arg_transport != TRANSPORT_SSH) {
+                int flags = (arg_lines*OUTPUT_SHOW_ALL |
+                             arg_follow*OUTPUT_FOLLOW |
+                             !arg_quiet*OUTPUT_WARN_CUTOFF);
                 printf("\n");
-                show_journal_by_unit(i->id, arg_output, 0, i->inactive_exit_timestamp_monotonic, arg_lines, arg_all, arg_follow, !arg_quiet);
+                show_journal_by_unit(i->id, arg_output, 0,
+                                     i->inactive_exit_timestamp_monotonic,
+                                     arg_lines, flags);
         }
 
         if (i->need_daemon_reload)

commit 25277cd7fbd77e4c8b20572570aa77c7da9abcc2
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Jul 17 07:35:06 2012 +0200

    logs: Adapt interface in log-show.c (output_journal)
    
    In preparation for adding more output switches, convert a series of
    flags arguments into one flag variable.

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 0d37107..016750c 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -434,7 +434,8 @@ int main(int argc, char *argv[]) {
 
                         line ++;
 
-                        r = output_journal(j, arg_output, line, 0, arg_show_all);
+                        r = output_journal(j, arg_output, line, 0,
+                                           arg_show_all ? OUTPUT_SHOW_ALL : 0);
                         if (r < 0)
                                 goto finish;
 
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 426a9d6..af9bcbd 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -77,7 +77,8 @@ static bool shall_print(bool show_all, char *p, size_t l) {
         return true;
 }
 
-static int output_short(sd_journal *j, unsigned line, unsigned n_columns, bool show_all, bool monotonic_mode) {
+static int output_short(sd_journal *j, unsigned line, unsigned n_columns,
+                        OutputFlags flags) {
         int r;
         const void *data;
         size_t length;
@@ -141,7 +142,7 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns, bool s
                 goto finish;
         }
 
-        if (monotonic_mode) {
+        if (flags & OUTPUT_MONOTONIC_MODE) {
                 uint64_t t;
                 sd_id128_t boot_id;
 
@@ -193,29 +194,33 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns, bool s
                 n += strlen(buf);
         }
 
-        if (hostname && shall_print(show_all, hostname, hostname_len)) {
+        if (hostname && shall_print(flags & OUTPUT_SHOW_ALL,
+                                    hostname, hostname_len)) {
                 printf(" %.*s", (int) hostname_len, hostname);
                 n += hostname_len + 1;
         }
 
-        if (identifier && shall_print(show_all, identifier, identifier_len)) {
+        if (identifier && shall_print(flags & OUTPUT_SHOW_ALL,
+                                      identifier, identifier_len)) {
                 printf(" %.*s", (int) identifier_len, identifier);
                 n += identifier_len + 1;
-        } else if (comm && shall_print(show_all, comm, comm_len)) {
+        } else if (comm && shall_print(flags & OUTPUT_SHOW_ALL,
+                                       comm, comm_len)) {
                 printf(" %.*s", (int) comm_len, comm);
                 n += comm_len + 1;
         } else
                 putchar(' ');
 
-        if (pid && shall_print(show_all, pid, pid_len)) {
+        if (pid && shall_print(flags & OUTPUT_SHOW_ALL, pid, pid_len)) {
                 printf("[%.*s]", (int) pid_len, pid);
                 n += pid_len + 2;
-        } else if (fake_pid && shall_print(show_all, fake_pid, fake_pid_len)) {
+        } else if (fake_pid && shall_print(flags & OUTPUT_SHOW_ALL,
+                                           fake_pid, fake_pid_len)) {
                 printf("[%.*s]", (int) fake_pid_len, fake_pid);
                 n += fake_pid_len + 2;
         }
 
-        if (show_all)
+        if (flags & OUTPUT_SHOW_ALL)
                 printf(": %.*s\n", (int) message_len, message);
         else if (!utf8_is_printable_n(message, message_len)) {
                 char bytes[FORMAT_BYTES_MAX];
@@ -251,15 +256,18 @@ finish:
         return r;
 }
 
-static int output_short_realtime(sd_journal *j, unsigned line, unsigned n_columns, bool show_all) {
-        return output_short(j, line, n_columns, show_all, false);
+static int output_short_realtime(sd_journal *j, unsigned line,
+                                 unsigned n_columns, OutputFlags flags) {
+        return output_short(j, line, n_columns, flags & ~OUTPUT_MONOTONIC_MODE);
 }
 
-static int output_short_monotonic(sd_journal *j, unsigned line, unsigned n_columns, bool show_all) {
-        return output_short(j, line, n_columns, show_all, true);
+static int output_short_monotonic(sd_journal *j, unsigned line,
+                                  unsigned n_columns, OutputFlags flags) {
+        return output_short(j, line, n_columns, flags | OUTPUT_MONOTONIC_MODE);
 }
 
-static int output_verbose(sd_journal *j, unsigned line, unsigned n_columns, bool show_all) {
+static int output_verbose(sd_journal *j, unsigned line,
+                          unsigned n_columns, OutputFlags flags) {
         const void *data;
         size_t length;
         char *cursor;
@@ -288,7 +296,7 @@ static int output_verbose(sd_journal *j, unsigned line, unsigned n_columns, bool
         free(cursor);
 
         SD_JOURNAL_FOREACH_DATA(j, data, length) {
-                if (!show_all && (length > PRINT_THRESHOLD ||
+                if (!(flags & OUTPUT_SHOW_ALL) && (length > PRINT_THRESHOLD ||
                                   !utf8_is_printable_n(data, length))) {
                         const char *c;
                         char bytes[FORMAT_BYTES_MAX];
@@ -310,7 +318,8 @@ static int output_verbose(sd_journal *j, unsigned line, unsigned n_columns, bool
         return 0;
 }
 
-static int output_export(sd_journal *j, unsigned line, unsigned n_columns, bool show_all) {
+static int output_export(sd_journal *j, unsigned line,
+                         unsigned n_columns, OutputFlags flags) {
         sd_id128_t boot_id;
         char sid[33];
         int r;
@@ -421,7 +430,8 @@ static void json_escape(const char* p, size_t l) {
         }
 }
 
-static int output_json(sd_journal *j, unsigned line, unsigned n_columns, bool show_all) {
+static int output_json(sd_journal *j, unsigned line,
+                       unsigned n_columns, OutputFlags flags) {
         uint64_t realtime, monotonic;
         char *cursor;
         const void *data;
@@ -494,7 +504,8 @@ static int output_json(sd_journal *j, unsigned line, unsigned n_columns, bool sh
         return 0;
 }
 
-static int output_cat(sd_journal *j, unsigned line, unsigned n_columns, bool show_all) {
+static int output_cat(sd_journal *j, unsigned line,
+                      unsigned n_columns, OutputFlags flags) {
         const void *data;
         size_t l;
         int r;
@@ -515,7 +526,8 @@ static int output_cat(sd_journal *j, unsigned line, unsigned n_columns, bool sho
         return 0;
 }
 
-static int (*output_funcs[_OUTPUT_MODE_MAX])(sd_journal*j, unsigned line, unsigned n_columns, bool show_all) = {
+static int (*output_funcs[_OUTPUT_MODE_MAX])(sd_journal*j, unsigned line,
+                                             unsigned n_columns, OutputFlags flags) = {
         [OUTPUT_SHORT] = output_short_realtime,
         [OUTPUT_SHORT_MONOTONIC] = output_short_monotonic,
         [OUTPUT_VERBOSE] = output_verbose,
@@ -524,14 +536,15 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(sd_journal*j, unsigned line, unsign
         [OUTPUT_CAT] = output_cat
 };
 
-int output_journal(sd_journal *j, OutputMode mode, unsigned line, unsigned n_columns, bool show_all) {
+int output_journal(sd_journal *j, OutputMode mode, unsigned line,
+                   unsigned n_columns, OutputFlags flags) {
         assert(mode >= 0);
         assert(mode < _OUTPUT_MODE_MAX);
 
         if (n_columns <= 0)
                 n_columns = columns();
 
-        return output_funcs[mode](j, line, n_columns, show_all);
+        return output_funcs[mode](j, line, n_columns, flags);
 }
 
 int show_journal_by_unit(
@@ -620,7 +633,8 @@ int show_journal_by_unit(
 
                         line ++;
 
-                        r = output_journal(j, mode, line, n_columns, show_all);
+                        r = output_journal(j, mode, line, n_columns,
+                                           show_all ? OUTPUT_SHOW_ALL : 0);
                         if (r < 0)
                                 goto finish;
                 }
diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h
index f8a9d40..beade06 100644
--- a/src/shared/logs-show.h
+++ b/src/shared/logs-show.h
@@ -39,7 +39,13 @@ typedef enum OutputMode {
         _OUTPUT_MODE_INVALID = -1
 } OutputMode;
 
-int output_journal(sd_journal *j, OutputMode mode, unsigned line, unsigned n_columns, bool show_all);
+typedef enum OutputFlags {
+        OUTPUT_SHOW_ALL = 1 << 0,
+        OUTPUT_MONOTONIC_MODE = 1 << 1,
+} OutputFlags;
+
+int output_journal(sd_journal *j, OutputMode mode, unsigned line,
+                   unsigned n_columns, OutputFlags flags);
 
 int show_journal_by_unit(
                 const char *unit,



More information about the systemd-commits mailing list