From faf20d4cca04cb9d08d098d4d9748e493648703b Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 14 Mar 2022 18:16:15 +0100 Subject: [PATCH 1/3] journal: reset previously set JSON flags Make sure we reset the JSON format flags if the format option is used multiple times, e.g. `journalctl -o json-format -o export`. Pointed out in: https://github.com/systemd/systemd/pull/22721#discussion_r826018985 Follow-up for: 5a1355d848a0f6564a04c6d8268e72bc93d173de --- src/journal/journalctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 4e3d17678e..e0951f9682 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -581,6 +581,9 @@ static int parse_argv(int argc, char *argv[]) { if (OUTPUT_MODE_IS_JSON(arg_output)) arg_json_format_flags = output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO; + else + arg_json_format_flags = JSON_FORMAT_OFF; + break; case 'l': From 8e4b9a252b434b7f8c74271df8dc4f07d7960c32 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 14 Mar 2022 18:26:53 +0100 Subject: [PATCH 2/3] journal: use table_set_json_field_name() to override a column name Pointed out in: https://github.com/systemd/systemd/pull/22721#discussion_r826014227 Follow-up for: 5a1355d848a0f6564a04c6d8268e72bc93d173de --- src/journal/journalctl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index e0951f9682..55c48eded5 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1460,13 +1460,17 @@ static int list_boots(sd_journal *j) { if (count == 0) return count; - table = table_new(OUTPUT_MODE_IS_JSON(arg_output) ? "index" : "idx", "boot id", "first entry", "last entry"); + table = table_new("idx", "boot id", "first entry", "last entry"); if (!table) return log_oom(); if (arg_full) table_set_width(table, 0); + r = table_set_json_field_name(table, 0, "index"); + if (r < 0) + return log_error_errno(r, "Failed to set JSON field name of column 0: %m"); + i = 0; LIST_FOREACH(boot_list, id, all_ids) { r = table_add_many(table, From f01aafd283e0302d12ab7e7f31675c302bf5d798 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 14 Mar 2022 18:43:03 +0100 Subject: [PATCH 3/3] journal: make --reverse affect --list-boots Fixes: #16274 --- src/journal/journalctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 55c48eded5..63334c0ea4 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1471,6 +1471,9 @@ static int list_boots(sd_journal *j) { if (r < 0) return log_error_errno(r, "Failed to set JSON field name of column 0: %m"); + (void) table_set_sort(table, (size_t) 0); + (void) table_set_reverse(table, 0, arg_reverse); + i = 0; LIST_FOREACH(boot_list, id, all_ids) { r = table_add_many(table,