summaryrefslogtreecommitdiffstats
path: root/src/journal
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-04-25 06:15:49 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-08-01 00:31:44 +0200
commitb3a16f39850d60c372cc13c62228544a1fb27ae6 (patch)
tree65ca2c782e711362c34684c9ec3474af30865931 /src/journal
parentjournalctl: update log messages (diff)
downloadsystemd-b3a16f39850d60c372cc13c62228544a1fb27ae6.tar.xz
systemd-b3a16f39850d60c372cc13c62228544a1fb27ae6.zip
journalctl: split out show_log_ids() from action_list_boots()
No functional change, just refactoring and prepraration for later change.
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journalctl-misc.c52
1 files changed, 31 insertions, 21 deletions
diff --git a/src/journal/journalctl-misc.c b/src/journal/journalctl-misc.c
index 880a0900eb..bc063d930b 100644
--- a/src/journal/journalctl-misc.c
+++ b/src/journal/journalctl-misc.c
@@ -98,31 +98,15 @@ int action_disk_usage(void) {
return 0;
}
-int action_list_boots(void) {
- _cleanup_(sd_journal_closep) sd_journal *j = NULL;
+static int show_log_ids(const LogId *ids, size_t n_ids, const char *name) {
_cleanup_(table_unrefp) Table *table = NULL;
- _cleanup_free_ LogId *ids = NULL;
- size_t n_ids;
int r;
- assert(arg_action == ACTION_LIST_BOOTS);
-
- r = acquire_journal(&j);
- if (r < 0)
- return r;
+ assert(ids);
+ assert(n_ids > 0);
+ assert(name);
- r = journal_get_boots(
- j,
- /* advance_older = */ arg_lines_needs_seek_end(),
- /* max_ids = */ arg_lines >= 0 ? (size_t) arg_lines : SIZE_MAX,
- &ids, &n_ids);
- if (r < 0)
- return log_error_errno(r, "Failed to determine boots: %m");
- if (r == 0)
- return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_ERR, SYNTHETIC_ERRNO(ENODATA),
- "No boot found.");
-
- table = table_new("idx", "boot id", "first entry", "last entry");
+ table = table_new("idx", name, "first entry", "last entry");
if (!table)
return log_oom();
@@ -166,6 +150,32 @@ int action_list_boots(void) {
return 0;
}
+int action_list_boots(void) {
+ _cleanup_(sd_journal_closep) sd_journal *j = NULL;
+ _cleanup_free_ LogId *ids = NULL;
+ size_t n_ids;
+ int r;
+
+ assert(arg_action == ACTION_LIST_BOOTS);
+
+ r = acquire_journal(&j);
+ if (r < 0)
+ return r;
+
+ r = journal_get_boots(
+ j,
+ /* advance_older = */ arg_lines_needs_seek_end(),
+ /* max_ids = */ arg_lines >= 0 ? (size_t) arg_lines : SIZE_MAX,
+ &ids, &n_ids);
+ if (r < 0)
+ return log_error_errno(r, "Failed to determine boots: %m");
+ if (r == 0)
+ return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_ERR, SYNTHETIC_ERRNO(ENODATA),
+ "No boot found.");
+
+ return show_log_ids(ids, n_ids, "boot id");
+}
+
int action_list_fields(void) {
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
int r, n_shown = 0;