dryang / rpms / systemd

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