chiark / gitweb /
logs: Adapt interface in log-show.c (output_journal)
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 Jul 2012 05:35:06 +0000 (07:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Jul 2012 15:20:57 +0000 (17:20 +0200)
In preparation for adding more output switches, convert a series of
flags arguments into one flag variable.

src/journal/journalctl.c
src/shared/logs-show.c
src/shared/logs-show.h

index 0d37107874f262f41b128e48a04e689a4fb8d431..016750c20153cbaca13462d68526415ed051fdba 100644 (file)
@@ -434,7 +434,8 @@ int main(int argc, char *argv[]) {
 
                         line ++;
 
 
                         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;
 
                         if (r < 0)
                                 goto finish;
 
index 426a9d617cf2678117ac7efafc781b6080ed81e5..af9bcbd0f7e25ef0c2a70088ae7f70bb18d631ef 100644 (file)
@@ -77,7 +77,8 @@ static bool shall_print(bool show_all, char *p, size_t l) {
         return true;
 }
 
         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;
         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;
         }
 
                 goto finish;
         }
 
-        if (monotonic_mode) {
+        if (flags & OUTPUT_MONOTONIC_MODE) {
                 uint64_t t;
                 sd_id128_t boot_id;
 
                 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);
         }
 
                 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;
         }
 
                 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;
                 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(' ');
 
                 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;
                 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;
         }
 
                 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];
                 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;
 }
 
         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;
         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) {
         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];
                                   !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;
 }
 
         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;
         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;
         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;
 }
 
         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;
         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;
 }
 
         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,
         [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
 };
 
         [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();
 
         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(
 }
 
 int show_journal_by_unit(
@@ -620,7 +633,8 @@ int show_journal_by_unit(
 
                         line ++;
 
 
                         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;
                 }
                         if (r < 0)
                                 goto finish;
                 }
index f8a9d406bde3b65dc5df080454c8d5360557913e..beade06a78312259ab4fa0cbfdee65f629559c39 100644 (file)
@@ -39,7 +39,13 @@ typedef enum OutputMode {
         _OUTPUT_MODE_INVALID = -1
 } 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,
 
 int show_journal_by_unit(
                 const char *unit,