chiark / gitweb /
sd-event: fix prepare priority queue comparison function
authorKrzysztof Kotlenga <k.kotlenga@sims.pl>
Wed, 23 Sep 2015 22:34:51 +0000 (00:34 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 29 Mar 2017 08:45:10 +0000 (10:45 +0200)
Otherwise a disabled event source can get swapped with an enabled one
and cause a severe sd-event malfunction.

http://lists.freedesktop.org/archives/elogind-devel/2015-September/034356.html

src/libelogind/sd-event/sd-event.c

index 062f19b56790e0e27d7c1c99a2205a0c706aee2a..bb5905fea16be8c0e70989d16b5d2ba9c26e61e3 100644 (file)
@@ -257,6 +257,12 @@ static int prepare_prioq_compare(const void *a, const void *b) {
         assert(x->prepare);
         assert(y->prepare);
 
+        /* Enabled ones first */
+        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
+                return -1;
+        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
+                return 1;
+
         /* Move most recently prepared ones last, so that we can stop
          * preparing as soon as we hit one that has already been
          * prepared in the current iteration */
@@ -265,12 +271,6 @@ static int prepare_prioq_compare(const void *a, const void *b) {
         if (x->prepare_iteration > y->prepare_iteration)
                 return 1;
 
-        /* Enabled ones first */
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
-                return -1;
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
-                return 1;
-
         /* Lower priority values first */
         if (x->priority < y->priority)
                 return -1;