dcavalca / rpms / systemd

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