Blame SOURCES/0483-Avoid-forever-loop-for-journalctl-list-boots-command.patch

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