teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0602-sd-event-use-CMP-macro.patch

b677e7
From 7419222d3811d60c0a8f5ea27778108a1ca8ee71 Mon Sep 17 00:00:00 2001
b677e7
From: Yu Watanabe <watanabe.yu+github@gmail.com>
b677e7
Date: Tue, 15 Jun 2021 00:51:33 +0900
b677e7
Subject: [PATCH] sd-event: use CMP() macro
b677e7
b677e7
(cherry picked from commit 06e131477d82b83c5d516e66d6e413affd7c774a)
b677e7
b677e7
Related: #1968528
b677e7
---
b677e7
 src/libsystemd/sd-event/sd-event.c | 37 ++++++++++++++----------------
b677e7
 1 file changed, 17 insertions(+), 20 deletions(-)
b677e7
b677e7
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
b677e7
index 2b0b76aa1c..6a20b658e4 100644
b677e7
--- a/src/libsystemd/sd-event/sd-event.c
b677e7
+++ b/src/libsystemd/sd-event/sd-event.c
b677e7
@@ -358,10 +358,9 @@ static int pending_prioq_compare(const void *a, const void *b) {
b677e7
         assert(y->pending);
b677e7
 
b677e7
         /* Enabled ones first */
b677e7
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
b677e7
-                return -1;
b677e7
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
b677e7
-                return 1;
b677e7
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
b677e7
+        if (r != 0)
b677e7
+                return r;
b677e7
 
b677e7
         /* Non rate-limited ones first. */
b677e7
         r = CMP(!!x->ratelimited, !!y->ratelimited);
b677e7
@@ -385,10 +384,9 @@ static int prepare_prioq_compare(const void *a, const void *b) {
b677e7
         assert(y->prepare);
b677e7
 
b677e7
         /* Enabled ones first */
b677e7
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
b677e7
-                return -1;
b677e7
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
b677e7
-                return 1;
b677e7
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
b677e7
+        if (r != 0)
b677e7
+                return r;
b677e7
 
b677e7
         /* Non rate-limited ones first. */
b677e7
         r = CMP(!!x->ratelimited, !!y->ratelimited);
b677e7
@@ -455,18 +453,17 @@ static bool event_source_timer_candidate(const sd_event_source *s) {
b677e7
 
b677e7
 static int time_prioq_compare(const void *a, const void *b, usec_t (*time_func)(const sd_event_source *s)) {
b677e7
         const sd_event_source *x = a, *y = b;
b677e7
+        int r;
b677e7
 
b677e7
         /* Enabled ones first */
b677e7
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
b677e7
-                return -1;
b677e7
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
b677e7
-                return 1;
b677e7
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
b677e7
+        if (r != 0)
b677e7
+                return r;
b677e7
 
b677e7
         /* Order "non-pending OR ratelimited" before "pending AND not-ratelimited" */
b677e7
-        if (event_source_timer_candidate(x) && !event_source_timer_candidate(y))
b677e7
-                return -1;
b677e7
-        if (!event_source_timer_candidate(x) && event_source_timer_candidate(y))
b677e7
-                return 1;
b677e7
+        r = CMP(!event_source_timer_candidate(x), !event_source_timer_candidate(y));
b677e7
+        if (r != 0)
b677e7
+                return r;
b677e7
 
b677e7
         /* Order by time */
b677e7
         return CMP(time_func(x), time_func(y));
b677e7
@@ -482,15 +479,15 @@ static int latest_time_prioq_compare(const void *a, const void *b) {
b677e7
 
b677e7
 static int exit_prioq_compare(const void *a, const void *b) {
b677e7
         const sd_event_source *x = a, *y = b;
b677e7
+        int r;
b677e7
 
b677e7
         assert(x->type == SOURCE_EXIT);
b677e7
         assert(y->type == SOURCE_EXIT);
b677e7
 
b677e7
         /* Enabled ones first */
b677e7
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
b677e7
-                return -1;
b677e7
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
b677e7
-                return 1;
b677e7
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
b677e7
+        if (r != 0)
b677e7
+                return r;
b677e7
 
b677e7
         /* Lower priority values first */
b677e7
         if (x->priority < y->priority)