summaryrefslogtreecommitdiff
path: root/src/shared/logs-show.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/logs-show.c')
-rw-r--r--src/shared/logs-show.c111
1 files changed, 50 insertions, 61 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index b83f543ba8..2bfd0b60c2 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -1181,85 +1181,74 @@ int show_journal(
}
for (;;) {
- for (;;) {
- usec_t usec;
+ usec_t usec;
- if (need_seek) {
- r = sd_journal_next(j);
- if (r < 0)
- return log_error_errno(r, "Failed to iterate through journal: %m");
- }
-
- if (r == 0)
- break;
+ if (need_seek) {
+ r = sd_journal_next(j);
+ if (r < 0)
+ return log_error_errno(r, "Failed to iterate through journal: %m");
+ }
- need_seek = true;
+ if (r == 0)
+ break;
- if (not_before > 0) {
- r = sd_journal_get_monotonic_usec(j, &usec, NULL);
+ need_seek = true;
- /* -ESTALE is returned if the
- timestamp is not from this boot */
- if (r == -ESTALE)
- continue;
- else if (r < 0)
- return log_error_errno(r, "Failed to get journal time: %m");
+ if (not_before > 0) {
+ r = sd_journal_get_monotonic_usec(j, &usec, NULL);
- if (usec < not_before)
- continue;
- }
+ /* -ESTALE is returned if the timestamp is not from this boot */
+ if (r == -ESTALE)
+ continue;
+ else if (r < 0)
+ return log_error_errno(r, "Failed to get journal time: %m");
- line++;
- maybe_print_begin_newline(f, &flags);
-
- r = show_journal_entry(f, j, mode, n_columns, flags, NULL, NULL, ellipsized);
- if (r < 0)
- return r;
+ if (usec < not_before)
+ continue;
}
- if (warn_cutoff && line < how_many && not_before > 0) {
- sd_id128_t boot_id;
- usec_t cutoff = 0;
-
- /* Check whether the cutoff line is too early */
+ line++;
+ maybe_print_begin_newline(f, &flags);
- r = sd_id128_get_boot(&boot_id);
- if (r < 0)
- return log_error_errno(r, "Failed to get boot id: %m");
+ r = show_journal_entry(f, j, mode, n_columns, flags, NULL, NULL, ellipsized);
+ if (r < 0)
+ return r;
+ }
- r = sd_journal_get_cutoff_monotonic_usec(j, boot_id, &cutoff, NULL);
- if (r < 0)
- return log_error_errno(r, "Failed to get journal cutoff time: %m");
+ if (warn_cutoff && line < how_many && not_before > 0) {
+ sd_id128_t boot_id;
+ usec_t cutoff = 0;
- if (r > 0 && not_before < cutoff) {
- maybe_print_begin_newline(f, &flags);
+ /* Check whether the cutoff line is too early */
- /* If we logged *something* and no permission error happened, than we can
- * reliably emit the warning about rotation. If we didn't log anything and
- * access errors happened, emit hint about permissions. Otherwise, give a
- * generic message, since we can't diagnose the issue. */
+ r = sd_id128_get_boot(&boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get boot id: %m");
- bool noaccess = journal_access_blocked(j);
+ r = sd_journal_get_cutoff_monotonic_usec(j, boot_id, &cutoff, NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get journal cutoff time: %m");
- if (line == 0 && noaccess)
- fprintf(f, "Warning: some journal files were not opened due to insufficient permissions.");
- else if (!noaccess)
- fprintf(f, "Warning: journal has been rotated since unit was started, output may be incomplete.\n");
- else
- fprintf(f, "Warning: journal has been rotated since unit was started and some journal "
- "files were not opened due to insufficient permissions, output may be incomplete.\n");
- }
+ if (r > 0 && not_before < cutoff) {
+ maybe_print_begin_newline(f, &flags);
- warn_cutoff = false;
- }
+ /* If we logged *something* and no permission error happened, than we can reliably
+ * emit the warning about rotation. If we didn't log anything and access errors
+ * happened, emit hint about permissions. Otherwise, give a generic message, since we
+ * can't diagnose the issue. */
- if (!(flags & OUTPUT_FOLLOW))
- break;
+ bool noaccess = journal_access_blocked(j);
- r = sd_journal_wait(j, USEC_INFINITY);
- if (r < 0)
- return log_error_errno(r, "Failed to wait for journal: %m");
+ if (line == 0 && noaccess)
+ fprintf(f, "Warning: some journal files were not opened due to insufficient permissions.");
+ else if (!noaccess)
+ fprintf(f, "Warning: journal has been rotated since unit was started, output may be incomplete.\n");
+ else
+ fprintf(f, "Warning: journal has been rotated since unit was started and some journal "
+ "files were not opened due to insufficient permissions, output may be incomplete.\n");
+ }
+ warn_cutoff = false;
}
return 0;