chiark / gitweb /
shared: logs-show: fflush after each output type
[elogind.git] / src / shared / logs-show.c
index c72ebc11f57c1644ec777249299b5d31c0fba737..67b20563dffae74ce1b0cb74d09853426508a80e 100644 (file)
@@ -246,7 +246,7 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns,
                 char bytes[FORMAT_BYTES_MAX];
                 printf(": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
         } else if ((flags & OUTPUT_FULL_WIDTH) ||
-                   (message_len + n < n_columns))
+                   (message_len + n + 1 < n_columns))
                 printf(": %s%.*s%s\n", color_on, (int) message_len, message, color_off);
         else if (n < n_columns && n_columns - n - 2 >= 3) {
                 char *e;
@@ -273,6 +273,7 @@ finish:
         free(message);
         free(monotonic);
         free(realtime);
+        free(priority);
 
         return r;
 }
@@ -520,7 +521,6 @@ static int output_json(sd_journal *j, unsigned line,
         }
 
         fputs("\n}", stdout);
-        fflush(stdout);
 
         return 0;
 }
@@ -559,13 +559,16 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(sd_journal*j, unsigned line,
 
 int output_journal(sd_journal *j, OutputMode mode, unsigned line,
                    unsigned n_columns, OutputFlags flags) {
+        int ret;
         assert(mode >= 0);
         assert(mode < _OUTPUT_MODE_MAX);
 
         if (n_columns <= 0)
                 n_columns = columns();
 
-        return output_funcs[mode](j, line, n_columns, flags);
+        ret = output_funcs[mode](j, line, n_columns, flags);
+        fflush(stdout);
+        return ret;
 }
 
 int show_journal_by_unit(
@@ -576,7 +579,7 @@ int show_journal_by_unit(
                 unsigned how_many,
                 OutputFlags flags) {
 
-        char *m = NULL;
+        char *m1 = NULL, *m2 = NULL, *m3 = NULL;
         sd_journal *j = NULL;
         int r;
         unsigned line = 0;
@@ -596,7 +599,9 @@ int show_journal_by_unit(
         if (how_many <= 0)
                 return 0;
 
-        if (asprintf(&m, "_SYSTEMD_UNIT=%s", unit) < 0) {
+        if (asprintf(&m1, "_SYSTEMD_UNIT=%s", unit) < 0 ||
+            asprintf(&m2, "COREDUMP_UNIT=%s", unit) < 0 ||
+            asprintf(&m3, "UNIT=%s", unit) < 0) {
                 r = -ENOMEM;
                 goto finish;
         }
@@ -605,10 +610,34 @@ int show_journal_by_unit(
         if (r < 0)
                 goto finish;
 
-        r = sd_journal_add_match(j, m, strlen(m));
+        /* Look for messages from the service itself */
+        r = sd_journal_add_match(j, m1, 0);
+        if (r < 0)
+                goto finish;
+
+        /* Look for coredumps of the service */
+        r = sd_journal_add_disjunction(j);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, "MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1", 0);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, m2, 0);
+        if (r < 0)
+                goto finish;
+
+        /* Look for messages from PID 1 about this service */
+        r = sd_journal_add_disjunction(j);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, "_PID=1", 0);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, m3, 0);
         if (r < 0)
                 goto finish;
 
+        /* Seek to end */
         r = sd_journal_seek_tail(j);
         if (r < 0)
                 goto finish;
@@ -691,8 +720,9 @@ int show_journal_by_unit(
                 fputs("\n]\n", stdout);
 
 finish:
-        if (m)
-                free(m);
+        free(m1);
+        free(m2);
+        free(m3);
 
         if (j)
                 sd_journal_close(j);