teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0557-sd-event-update-state-at-the-end-in-event_source_ena.patch

b677e7
From deb9e6ad3a1d7cfbc3b53d1e74cda6ae398a90fd Mon Sep 17 00:00:00 2001
b677e7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
b677e7
Date: Tue, 10 Nov 2020 10:38:37 +0100
b677e7
Subject: [PATCH] sd-event: update state at the end in event_source_enable
b677e7
b677e7
Coverity in CID#1435966 was complaining that s->enabled is not "restored" in
b677e7
all cases. But the code was actually correct, since it should only be
b677e7
"restored" in the error paths. But let's still make this prettier by not setting
b677e7
the state before all operations that may fail are done.
b677e7
b677e7
We need to set .enabled for the prioq reshuffling operations, so move those down.
b677e7
b677e7
No functional change intended.
b677e7
b677e7
(cherry picked from commit d2eafe61ca07f8300dc741a0491a914213fa2b6b)
b677e7
b677e7
Related: #1819868
b677e7
---
b677e7
 src/libsystemd/sd-event/sd-event.c | 51 +++++++++++++++++-------------
b677e7
 1 file changed, 29 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 34b42c298f..0cfba8fb39 100644
b677e7
--- a/src/libsystemd/sd-event/sd-event.c
b677e7
+++ b/src/libsystemd/sd-event/sd-event.c
b677e7
@@ -2352,11 +2352,11 @@ static int event_source_disable(sd_event_source *s) {
b677e7
         return 0;
b677e7
 }
b677e7
 
b677e7
-static int event_source_enable(sd_event_source *s, int m) {
b677e7
+static int event_source_enable(sd_event_source *s, int enable) {
b677e7
         int r;
b677e7
 
b677e7
         assert(s);
b677e7
-        assert(IN_SET(m, SD_EVENT_ON, SD_EVENT_ONESHOT));
b677e7
+        assert(IN_SET(enable, SD_EVENT_ON, SD_EVENT_ONESHOT));
b677e7
         assert(s->enabled == SD_EVENT_OFF);
b677e7
 
b677e7
         /* Unset the pending flag when this event source is enabled */
b677e7
@@ -2366,31 +2366,16 @@ static int event_source_enable(sd_event_source *s, int m) {
b677e7
                         return r;
b677e7
         }
b677e7
 
b677e7
-        s->enabled = m;
b677e7
-
b677e7
         switch (s->type) {
b677e7
-
b677e7
         case SOURCE_IO:
b677e7
-                r = source_io_register(s, m, s->io.events);
b677e7
-                if (r < 0) {
b677e7
-                        s->enabled = SD_EVENT_OFF;
b677e7
+                r = source_io_register(s, enable, s->io.events);
b677e7
+                if (r < 0)
b677e7
                         return r;
b677e7
-                }
b677e7
-
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
                 r = event_make_signal_data(s->event, s->signal.sig, NULL);
b677e7
                 if (r < 0) {
b677e7
-                        s->enabled = SD_EVENT_OFF;
b677e7
                         event_gc_signal_data(s->event, &s->priority, s->signal.sig);
b677e7
                         return r;
b677e7
                 }
b677e7
@@ -2411,10 +2396,12 @@ static int event_source_enable(sd_event_source *s, int m) {
b677e7
 
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_EXIT:
b677e7
-                prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
b677e7
-                break;
b677e7
-
b677e7
         case SOURCE_DEFER:
b677e7
         case SOURCE_POST:
b677e7
         case SOURCE_INOTIFY:
b677e7
@@ -2424,6 +2411,26 @@ static int event_source_enable(sd_event_source *s, int m) {
b677e7
                 assert_not_reached("Wut? I shouldn't exist.");
b677e7
         }
b677e7
 
b677e7
+        s->enabled = enable;
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
+                prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
b677e7
+                break;
b677e7
+
b677e7
+        default:
b677e7
+                break;
b677e7
+        }
b677e7
+
b677e7
         return 0;
b677e7
 }
b677e7