chiark / gitweb /
systemctl: suppress duplicate newline if there's not log output in "systemctl status"
authorLennart Poettering <lennart@poettering.net>
Thu, 13 Mar 2014 02:58:03 +0000 (03:58 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 13 Mar 2014 03:17:37 +0000 (04:17 +0100)
src/shared/logs-show.c
src/shared/output-mode.h
src/systemctl/systemctl.c

index 12d4a1caecae75fd8090e98adc3e001efe9e5d59..f7d84fc723d233bd05fde439356ac124125b4733 100644 (file)
@@ -927,6 +927,21 @@ int output_journal(
         return ret;
 }
 
+static int maybe_print_begin_newline(FILE *f, OutputFlags *flags) {
+        assert(f);
+        assert(flags);
+
+        if (!(*flags & OUTPUT_BEGIN_NEWLINE))
+                return 0;
+
+        /* Print a beginning new line if that's request, but only once
+         * on the first line we print. */
+
+        fputc('\n', f);
+        *flags &= ~OUTPUT_BEGIN_NEWLINE;
+        return 0;
+}
+
 static int show_journal(FILE *f,
                         sd_journal *j,
                         OutputMode mode,
@@ -984,6 +999,7 @@ static int show_journal(FILE *f,
                         }
 
                         line ++;
+                        maybe_print_begin_newline(f, &flags);
 
                         r = output_journal(f, j, mode, n_columns, flags, ellipsized);
                         if (r < 0)
@@ -1004,8 +1020,10 @@ static int show_journal(FILE *f,
                         if (r < 0)
                                 goto finish;
 
-                        if (r > 0 && not_before < cutoff)
+                        if (r > 0 && not_before < cutoff) {
+                                maybe_print_begin_newline(f, &flags);
                                 fprintf(f, "Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.\n");
+                        }
 
                         warn_cutoff = false;
                 }
index 9da789db762632a3aa6cf50858c50d65d15ad8e2..ac1bb0123b5fbcff4845b46211387c0307dc3e1c 100644 (file)
@@ -42,5 +42,6 @@ typedef enum OutputFlags {
         OUTPUT_WARN_CUTOFF    = 1 << 2,
         OUTPUT_FULL_WIDTH     = 1 << 3,
         OUTPUT_COLOR          = 1 << 4,
-        OUTPUT_CATALOG        = 1 << 5
+        OUTPUT_CATALOG        = 1 << 5,
+        OUTPUT_BEGIN_NEWLINE  = 1 << 6,
 } OutputFlags;
index 3cb10964fd22f504513c453d46e274d655efa5a7..21bf51bb3eb30617751f0d8afb5bcc54cd01cab7 100644 (file)
@@ -3226,7 +3226,6 @@ static void print_status_info(
         }
 
         if (i->id && arg_transport == BUS_TRANSPORT_LOCAL) {
-                printf("\n");
                 show_journal_by_unit(stdout,
                                      i->id,
                                      arg_output,
@@ -3234,7 +3233,7 @@ static void print_status_info(
                                      i->inactive_exit_timestamp_monotonic,
                                      arg_lines,
                                      getuid(),
-                                     flags,
+                                     flags | OUTPUT_BEGIN_NEWLINE,
                                      arg_scope == UNIT_FILE_SYSTEM,
                                      ellipsized);
         }