From 889e396046a8a52c16beee7aa6395dc32f854fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 16 May 2018 17:21:51 +0200 Subject: [PATCH] shared/logs-show: export show_journal() This is a nice function to output some journal entries without much ado. --- src/shared/logs-show.c | 35 ++++++++++++++++++++--------------- src/shared/logs-show.h | 9 +++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index e1d59209d7..50326fde5d 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1119,14 +1119,15 @@ static int maybe_print_begin_newline(FILE *f, OutputFlags *flags) { return 0; } -static int show_journal(FILE *f, - sd_journal *j, - OutputMode mode, - unsigned n_columns, - usec_t not_before, - unsigned how_many, - OutputFlags flags, - bool *ellipsized) { +int show_journal( + FILE *f, + sd_journal *j, + OutputMode mode, + unsigned n_columns, + usec_t not_before, + unsigned how_many, + OutputFlags flags, + bool *ellipsized) { int r; unsigned line = 0; @@ -1137,14 +1138,18 @@ static int show_journal(FILE *f, assert(mode >= 0); assert(mode < _OUTPUT_MODE_MAX); - /* Seek to end */ - r = sd_journal_seek_tail(j); - if (r < 0) - return log_error_errno(r, "Failed to seek to tail: %m"); + if (how_many == (unsigned) -1) + need_seek = true; + else { + /* Seek to end */ + r = sd_journal_seek_tail(j); + if (r < 0) + return log_error_errno(r, "Failed to seek to tail: %m"); - r = sd_journal_previous_skip(j, how_many); - if (r < 0) - return log_error_errno(r, "Failed to skip previous: %m"); + r = sd_journal_previous_skip(j, how_many); + if (r < 0) + return log_error_errno(r, "Failed to skip previous: %m"); + } for (;;) { for (;;) { diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index 49caa4cb39..68e234a0ef 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -28,6 +28,15 @@ int show_journal_entry( char **output_fields, size_t highlight[2], bool *ellipsized); +int show_journal( + FILE *f, + sd_journal *j, + OutputMode mode, + unsigned n_columns, + usec_t not_before, + unsigned how_many, + OutputFlags flags, + bool *ellipsized); int add_match_this_boot(sd_journal *j, const char *machine);