From: Yu Watanabe Date: Fri, 22 Mar 2024 08:40:37 +0000 (+0900) Subject: logs-show: read the current boot ID if nothing specified for add_match_boot_id() X-Git-Tag: v256-rc1~381^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0aad30d4b58dadd82ba88d89b2d52dccaaac92c7;p=thirdparty%2Fsystemd.git logs-show: read the current boot ID if nothing specified for add_match_boot_id() No functional change, just refactoring. --- diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index c7472538581..17565f260a1 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -512,15 +512,7 @@ static mhd_result request_parse_arguments_iterator( } if (r) { - sd_id128_t bid; - - r = sd_id128_get_boot(&bid); - if (r < 0) { - log_error_errno(r, "Failed to get boot ID: %m"); - return MHD_NO; - } - - r = add_match_boot_id(m->journal, bid); + r = add_match_boot_id(m->journal, SD_ID128_NULL); if (r < 0) { m->argument_parse_error = r; return MHD_NO; diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 8633e486479..bbcaf6825e1 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1636,10 +1636,21 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) { } int add_match_boot_id(sd_journal *j, sd_id128_t id) { + int r; + assert(j); - assert(!sd_id128_is_null(id)); - return journal_add_match_pair(j, "_BOOT_ID", SD_ID128_TO_STRING(id)); + if (sd_id128_is_null(id)) { + r = sd_id128_get_boot(&id); + if (r < 0) + return log_error_errno(r, "Failed to get boot ID: %m"); + } + + r = journal_add_match_pair(j, "_BOOT_ID", SD_ID128_TO_STRING(id)); + if (r < 0) + return log_error_errno(r, "Failed to add match: %m"); + + return 0; } int add_match_this_boot(sd_journal *j, const char *machine) { @@ -1655,7 +1666,7 @@ int add_match_this_boot(sd_journal *j, const char *machine) { r = add_match_boot_id(j, boot_id); if (r < 0) - return log_error_errno(r, "Failed to add match: %m"); + return r; r = sd_journal_add_conjunction(j); if (r < 0)