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