anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0344-journal-verify-don-t-hit-SIGFPE-when-determining-pro.patch

1abbee
From 1466d84c159c1a9d1839c1b346906b722e6311a3 Mon Sep 17 00:00:00 2001
1abbee
From: Lennart Poettering <lennart@poettering.net>
1abbee
Date: Fri, 24 Jul 2015 01:40:44 +0200
1abbee
Subject: [PATCH] journal-verify: don't hit SIGFPE when determining progress
1abbee
1abbee
If we determine the progress based on a number of objects available,
1abbee
don't blindly devide by the number of objects, given that it might be 0.
1abbee
1abbee
Cherry-picked from: 45c047b227d96e98e7076c15ae774ff6390dc403
1abbee
Related: #1350232
1abbee
---
1abbee
 src/journal/journal-verify.c | 16 +++++++++++++---
1abbee
 1 file changed, 13 insertions(+), 3 deletions(-)
1abbee
1abbee
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
181b3f
index b03335ef3..983217c1b 100644
1abbee
--- a/src/journal/journal-verify.c
1abbee
+++ b/src/journal/journal-verify.c
1abbee
@@ -69,6 +69,16 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
1abbee
         fflush(stdout);
1abbee
 }
1abbee
 
1abbee
+static uint64_t scale_progress(uint64_t scale, uint64_t p, uint64_t m) {
1abbee
+
1abbee
+        /* Calculates scale * p / m, but handles m == 0 safely, and saturates */
1abbee
+
1abbee
+        if (p >= m || m == 0)
1abbee
+                return scale;
1abbee
+
1abbee
+        return scale * p / m;
1abbee
+}
1abbee
+
1abbee
 static void flush_progress(void) {
1abbee
         unsigned n, i;
1abbee
 
1abbee
@@ -584,7 +594,7 @@ static int verify_hash_table(
1abbee
                 uint64_t last = 0, p;
1abbee
 
1abbee
                 if (show_progress)
1abbee
-                        draw_progress(0xC000 + (0x3FFF * i / n), last_usec);
1abbee
+                        draw_progress(0xC000 + scale_progress(0x3FFF, i, n), last_usec);
1abbee
 
1abbee
                 p = le64toh(f->data_hash_table[i].head_hash_offset);
1abbee
                 while (p != 0) {
1abbee
@@ -726,7 +736,7 @@ static int verify_entry_array(
1abbee
                 Object *o;
1abbee
 
1abbee
                 if (show_progress)
1abbee
-                        draw_progress(0x8000 + (0x3FFF * i / n), last_usec);
1abbee
+                        draw_progress(0x8000 + scale_progress(0x3FFF, i, n), last_usec);
1abbee
 
1abbee
                 if (a == 0) {
1abbee
                         error(a, "array chain too short at %"PRIu64" of %"PRIu64, i, n);
1abbee
@@ -863,7 +873,7 @@ int journal_file_verify(
1abbee
         p = le64toh(f->header->header_size);
1abbee
         while (p != 0) {
1abbee
                 if (show_progress)
1abbee
-                        draw_progress(0x7FFF * p / le64toh(f->header->tail_object_offset), &last_usec);
1abbee
+                        draw_progress(scale_progress(0x7FFF, p, le64toh(f->header->tail_object_offset)), &last_usec);
1abbee
 
1abbee
                 r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o);
1abbee
                 if (r < 0) {