summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-16 17:21:51 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-31 13:04:18 +0200
commit889e396046a8a52c16beee7aa6395dc32f854fd1 (patch)
tree850e625f7651a2b42855f409a856bdd9526669c1
parent9b972c9aab56292ac2934fd1942e1ba443a39df0 (diff)
downloadsystemd-889e396046a8a52c16beee7aa6395dc32f854fd1.tar.gz
systemd-889e396046a8a52c16beee7aa6395dc32f854fd1.tar.bz2
systemd-889e396046a8a52c16beee7aa6395dc32f854fd1.zip
shared/logs-show: export show_journal()
This is a nice function to output some journal entries without much ado.
-rw-r--r--src/shared/logs-show.c35
-rw-r--r--src/shared/logs-show.h9
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);