From: Yu Watanabe Date: Thu, 25 Apr 2024 04:15:49 +0000 (+0900) Subject: journalctl: split out show_log_ids() from action_list_boots() X-Git-Tag: v257-rc1~786^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3a16f39850d60c372cc13c62228544a1fb27ae6;p=thirdparty%2Fsystemd.git journalctl: split out show_log_ids() from action_list_boots() No functional change, just refactoring and prepraration for later change. --- diff --git a/src/journal/journalctl-misc.c b/src/journal/journalctl-misc.c index 880a0900ebf..bc063d930bc 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;