richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
812ca2
From 1ce5187fb47bec57de4d8d3fd0068072228ec5e3 Mon Sep 17 00:00:00 2001
812ca2
From: Yu Watanabe <watanabe.yu+github@gmail.com>
812ca2
Date: Tue, 15 Jun 2021 02:13:59 +0900
812ca2
Subject: [PATCH] sd-event: always reshuffle time prioq on changing
812ca2
 online/offline state
812ca2
812ca2
Before 81107b8419c39f726fd2805517a5b9faab204e59, the compare functions
812ca2
for the latest or earliest prioq did not handle ratelimited flag.
812ca2
So, it was ok to not reshuffle the time prioq when changing the flag.
812ca2
812ca2
But now, those two compare functions also compare the source is
812ca2
ratelimited or not. So, it is necessary to reshuffle the time prioq
812ca2
after changing the ratelimited flag.
812ca2
812ca2
Hopefully fixes #19903.
812ca2
812ca2
(cherry picked from commit 2115b9b6629eeba7bc9f42f757f38205febb1cb7)
812ca2
812ca2
Related: #1968528
812ca2
---
812ca2
 src/libsystemd/sd-event/sd-event.c | 33 ++++++++++--------------------
812ca2
 1 file changed, 11 insertions(+), 22 deletions(-)
812ca2
812ca2
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
812ca2
index ae46392901..f78da00c3a 100644
812ca2
--- a/src/libsystemd/sd-event/sd-event.c
812ca2
+++ b/src/libsystemd/sd-event/sd-event.c
812ca2
@@ -2390,14 +2390,6 @@ static int event_source_offline(
812ca2
                 source_io_unregister(s);
812ca2
                 break;
812ca2
 
812ca2
-        case SOURCE_TIME_REALTIME:
812ca2
-        case SOURCE_TIME_BOOTTIME:
812ca2
-        case SOURCE_TIME_MONOTONIC:
812ca2
-        case SOURCE_TIME_REALTIME_ALARM:
812ca2
-        case SOURCE_TIME_BOOTTIME_ALARM:
812ca2
-                event_source_time_prioq_reshuffle(s);
812ca2
-                break;
812ca2
-
812ca2
         case SOURCE_SIGNAL:
812ca2
                 event_gc_signal_data(s->event, &s->priority, s->signal.sig);
812ca2
                 break;
812ca2
@@ -2415,6 +2407,11 @@ static int event_source_offline(
812ca2
                 prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
812ca2
                 break;
812ca2
 
812ca2
+        case SOURCE_TIME_REALTIME:
812ca2
+        case SOURCE_TIME_BOOTTIME:
812ca2
+        case SOURCE_TIME_MONOTONIC:
812ca2
+        case SOURCE_TIME_REALTIME_ALARM:
812ca2
+        case SOURCE_TIME_BOOTTIME_ALARM:
812ca2
         case SOURCE_DEFER:
812ca2
         case SOURCE_POST:
812ca2
         case SOURCE_INOTIFY:
812ca2
@@ -2424,6 +2421,9 @@ static int event_source_offline(
812ca2
                 assert_not_reached("Wut? I shouldn't exist.");
812ca2
         }
812ca2
 
812ca2
+        /* Always reshuffle time prioq, as the ratelimited flag may be changed. */
812ca2
+        event_source_time_prioq_reshuffle(s);
812ca2
+
812ca2
         return 1;
812ca2
 }
812ca2
 
812ca2
@@ -2505,22 +2505,11 @@ static int event_source_online(
812ca2
         s->ratelimited = ratelimited;
812ca2
 
812ca2
         /* Non-failing operations below */
812ca2
-        switch (s->type) {
812ca2
-        case SOURCE_TIME_REALTIME:
812ca2
-        case SOURCE_TIME_BOOTTIME:
812ca2
-        case SOURCE_TIME_MONOTONIC:
812ca2
-        case SOURCE_TIME_REALTIME_ALARM:
812ca2
-        case SOURCE_TIME_BOOTTIME_ALARM:
812ca2
-                event_source_time_prioq_reshuffle(s);
812ca2
-                break;
812ca2
-
812ca2
-        case SOURCE_EXIT:
812ca2
+        if (s->type == SOURCE_EXIT)
812ca2
                 prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
812ca2
-                break;
812ca2
 
812ca2
-        default:
812ca2
-                break;
812ca2
-        }
812ca2
+        /* Always reshuffle time prioq, as the ratelimited flag may be changed. */
812ca2
+        event_source_time_prioq_reshuffle(s);
812ca2
 
812ca2
         return 1;
812ca2
 }