]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logs-show: read the current boot ID if nothing specified for add_match_boot_id() 31965/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Mar 2024 08:40:37 +0000 (17:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 26 Mar 2024 14:54:46 +0000 (23:54 +0900)
No functional change, just refactoring.

src/journal-remote/journal-gatewayd.c
src/shared/logs-show.c

index c7472538581d183fef76a025faba3d596eb78848..17565f260a132aed9c36f80aceedcbc0d36e9048 100644 (file)
@@ -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;
index 8633e486479c81550318a3e9156466dfda4c05cb..bbcaf6825e161ca880cca0c5ff36c8ed48a5d445 100644 (file)
@@ -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)