richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a19bc6
From 9576fa3ecf91fd4703e2180ac080fd975292730f Mon Sep 17 00:00:00 2001
a19bc6
From: hese10 <heikki.kemppainen@nokia.com>
a19bc6
Date: Wed, 12 Oct 2016 19:40:28 +0300
a19bc6
Subject: [PATCH] Avoid forever loop for journalctl --list-boots command
a19bc6
 (#4278)
a19bc6
a19bc6
When date is changed in system to future and normal user logs to new
a19bc6
journal file, and then date is changed back to present time, the
a19bc6
"journalctl --list-boot" command goes to forever loop. This commit tries
a19bc6
to fix this problem by checking first the boot id list if the found boot
a19bc6
id was already in that list. If it is found, then stopping the boot id
a19bc6
find loop.
a19bc6
a19bc6
(cherry picked from commit ec02a6c90a5d8b234db534ce3f8f1901f8532057)
a19bc6
a19bc6
Conflicts:
a19bc6
	src/journal/journalctl.c
a19bc6
Related: #1294516
a19bc6
---
a19bc6
 src/journal/journalctl.c | 9 ++++++++-
a19bc6
 1 file changed, 8 insertions(+), 1 deletion(-)
a19bc6
a19bc6
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
a19bc6
index 723854a..c771cff 100644
a19bc6
--- a/src/journal/journalctl.c
a19bc6
+++ b/src/journal/journalctl.c
a19bc6
@@ -1039,7 +1039,7 @@ static int get_boots(
a19bc6
 
a19bc6
         bool skip_once;
a19bc6
         int r, count = 0;
a19bc6
-        BootId *head = NULL, *tail = NULL;
a19bc6
+        BootId *head = NULL, *tail = NULL, *id;
a19bc6
         const bool advance_older = query_ref_boot && ref_boot_offset <= 0;
a19bc6
         sd_id128_t previous_boot_id;
a19bc6
 
a19bc6
@@ -1121,6 +1121,13 @@ static int get_boots(
a19bc6
                                 break;
a19bc6
                         }
a19bc6
                 } else {
a19bc6
+                        LIST_FOREACH(boot_list, id, head) {
a19bc6
+                                if (sd_id128_equal(id->id, current->id)) {
a19bc6
+                                        /* boot id already stored, something wrong with the journal files */
a19bc6
+                                        /* exiting as otherwise this problem would cause forever loop */
a19bc6
+                                        goto finish;
a19bc6
+                                }
a19bc6
+                        }
a19bc6
                         LIST_INSERT_AFTER(boot_list, head, tail, current);
a19bc6
                         tail = current;
a19bc6
                         current = NULL;