teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0423-shared-add-NULL-callback-check-in-one-more-place.patch

52b84b
From 48ab0db62ab23307e9f35a862a9c9b33ba3ef261 Mon Sep 17 00:00:00 2001
52b84b
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
52b84b
Date: Thu, 23 Apr 2020 14:53:54 +0200
52b84b
Subject: [PATCH] shared: add NULL callback check in one more place
52b84b
52b84b
Follow-up for 9f65637308.
52b84b
52b84b
(cherry picked from commit d3d53e5cd143bf96d1eb0e254f16fa8d458d38ce)
52b84b
52b84b
Related: #1830861
52b84b
---
52b84b
 src/shared/bus-wait-for-units.c | 31 +++++++++++++------------------
52b84b
 1 file changed, 13 insertions(+), 18 deletions(-)
52b84b
52b84b
diff --git a/src/shared/bus-wait-for-units.c b/src/shared/bus-wait-for-units.c
52b84b
index 63ba3fd422..ba97922764 100644
52b84b
--- a/src/shared/bus-wait-for-units.c
52b84b
+++ b/src/shared/bus-wait-for-units.c
52b84b
@@ -80,6 +80,15 @@ static WaitForItem *wait_for_item_free(WaitForItem *item) {
52b84b
 
52b84b
 DEFINE_TRIVIAL_CLEANUP_FUNC(WaitForItem*, wait_for_item_free);
52b84b
 
52b84b
+static void call_unit_callback_and_wait(BusWaitForUnits *d, WaitForItem *item, bool good) {
52b84b
+        d->current = item;
52b84b
+
52b84b
+        if (item->unit_callback)
52b84b
+                item->unit_callback(d, item->bus_path, good, item->userdata);
52b84b
+
52b84b
+        wait_for_item_free(item);
52b84b
+}
52b84b
+
52b84b
 static void bus_wait_for_units_clear(BusWaitForUnits *d) {
52b84b
         WaitForItem *item;
52b84b
 
52b84b
@@ -88,13 +97,8 @@ static void bus_wait_for_units_clear(BusWaitForUnits *d) {
52b84b
         d->slot_disconnected = sd_bus_slot_unref(d->slot_disconnected);
52b84b
         d->bus = sd_bus_unref(d->bus);
52b84b
 
52b84b
-        while ((item = hashmap_first(d->items))) {
52b84b
-                d->current = item;
52b84b
-
52b84b
-                if (item->unit_callback)
52b84b
-                        item->unit_callback(d, item->bus_path, false, item->userdata);
52b84b
-                wait_for_item_free(item);
52b84b
-        }
52b84b
+        while ((item = hashmap_first(d->items)))
52b84b
+                call_unit_callback_and_wait(d, item, false);
52b84b
 
52b84b
         d->items = hashmap_free(d->items);
52b84b
 }
52b84b
@@ -213,13 +217,7 @@ static void wait_for_item_check_ready(WaitForItem *item) {
52b84b
                         return;
52b84b
         }
52b84b
 
52b84b
-        if (item->unit_callback) {
52b84b
-                d->current = item;
52b84b
-                item->unit_callback(d, item->bus_path, true, item->userdata);
52b84b
-        }
52b84b
-
52b84b
-        wait_for_item_free(item);
52b84b
-
52b84b
+        call_unit_callback_and_wait(d, item, true);
52b84b
         bus_wait_for_units_check_ready(d);
52b84b
 }
52b84b
 
52b84b
@@ -304,10 +302,7 @@ static int on_get_all_properties(sd_bus_message *m, void *userdata, sd_bus_error
52b84b
                 log_debug_errno(sd_bus_error_get_errno(error), "GetAll() failed for %s: %s",
52b84b
                                 item->bus_path, error->message);
52b84b
 
52b84b
-                d->current = item;
52b84b
-                item->unit_callback(d, item->bus_path, false, item->userdata);
52b84b
-                wait_for_item_free(item);
52b84b
-
52b84b
+                call_unit_callback_and_wait(d, item, false);
52b84b
                 bus_wait_for_units_check_ready(d);
52b84b
                 return 0;
52b84b
         }