]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-util: move bus_message_hash_ops to bus-message-util
authorMike Yuan <me@yhndnzj.com>
Sat, 11 Jan 2025 16:10:43 +0000 (17:10 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 13 Jan 2025 15:24:44 +0000 (16:24 +0100)
src/home/homed-manager-bus.c
src/login/logind-brightness.c
src/shared/bus-message-util.c
src/shared/bus-message-util.h
src/shared/bus-util.c
src/shared/bus-util.h
src/systemctl/systemctl-list-units.c
src/timedate/timedated.c

index 69c7680b9e563e3bc2967d2e5768e0f284a24193..08c917aee2e95f62e5989d49e8dd0f0172cd1b9d 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-message-util.h"
 #include "bus-polkit.h"
 #include "format-util.h"
 #include "home-util.h"
@@ -704,17 +705,17 @@ static int method_rebalance(sd_bus_message *message, void *userdata, sd_bus_erro
         int r;
 
         r = manager_schedule_rebalance(m, /* immediately= */ true);
-        if (r == 0)
-                return sd_bus_reply_method_errorf(message, BUS_ERROR_REBALANCE_NOT_NEEDED, "No home directories need rebalancing.");
         if (r < 0)
                 return r;
+        if (r == 0)
+                return sd_bus_reply_method_errorf(message, BUS_ERROR_REBALANCE_NOT_NEEDED, "No home directories need rebalancing.");
 
         /* Keep a reference to this message, so that we can reply to it once we are done */
-        r = set_ensure_put(&m->rebalance_queued_method_calls, &bus_message_hash_ops, message);
+        r = set_ensure_consume(&m->rebalance_queued_method_calls, &bus_message_hash_ops, sd_bus_message_ref(message));
         if (r < 0)
                 return log_error_errno(r, "Failed to track rebalance bus message: %m");
+        assert(r > 0);
 
-        sd_bus_message_ref(message);
         return 1;
 }
 
index 40bcb39ce0ca79b9af3abcb688964869059ecdb0..b3e7718394a7e579004f013af03f98407e55bc2a 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "bus-message-util.h"
 #include "bus-util.h"
 #include "device-util.h"
 #include "hash-funcs.h"
@@ -173,10 +174,9 @@ static int set_add_message(Set **set, sd_bus_message *message) {
         if (r <= 0)
                 return r;
 
-        r = set_ensure_put(set, &bus_message_hash_ops, message);
+        r = set_ensure_consume(set, &bus_message_hash_ops, sd_bus_message_ref(message));
         if (r <= 0)
                 return r;
-        sd_bus_message_ref(message);
 
         return 1;
 }
index e93be9b3c5095ce5f89213189c904fc8eb782557..a6523ff00e025e581bf8afac688e959b3c14d7dc 100644 (file)
@@ -246,3 +246,7 @@ int bus_message_dump_fd(sd_bus_message *message) {
 
         return 0;
 }
+
+DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(bus_message_hash_ops,
+                                      void, trivial_hash_func, trivial_compare_func,
+                                      sd_bus_message, sd_bus_message_unref);
index 698960561ced8b5a423052195d1121473ee75767..baec1cb92b784a1854d06650386bb225a6cbf50a 100644 (file)
@@ -21,3 +21,5 @@ int bus_message_read_dns_servers(
 
 int bus_message_dump_string(sd_bus_message *message);
 int bus_message_dump_fd(sd_bus_message *message);
+
+extern const struct hash_ops bus_message_hash_ops;
index d6189deb1809b153f281e56d44232467833e9f62..9e875751e719aaae9b67b995e3ac885f2b8f31bb 100644 (file)
@@ -862,16 +862,6 @@ int bus_register_malloc_status(sd_bus *bus, const char *destination) {
         return 0;
 }
 
-static void bus_message_unref_wrapper(void *m) {
-        sd_bus_message_unref(m);
-}
-
-const struct hash_ops bus_message_hash_ops = {
-        .hash = trivial_hash_func,
-        .compare = trivial_compare_func,
-        .free_value = bus_message_unref_wrapper,
-};
-
 int bus_message_append_string_set(sd_bus_message *m, Set *set) {
         const char *s;
         int r;
index b08635fd36662aca60ff5b9ef40a27c1928f56a7..755421c11f51966002d00a6ebd4d085e3228a56f 100644 (file)
@@ -78,8 +78,6 @@ int bus_reply_pair_array(sd_bus_message *m, char **l);
 /* Listen to GetMallocInfo() calls to 'destination' and return malloc_info() via FD */
 int bus_register_malloc_status(sd_bus *bus, const char *destination);
 
-extern const struct hash_ops bus_message_hash_ops;
-
 int bus_message_append_string_set(sd_bus_message *m, Set *s);
 
 int bus_property_get_string_set(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
index a2f3074358e927dcf0094265ce787faae8054958..b7cb103513d79974f9bc94f99b70bf11683ed0bd 100644 (file)
@@ -5,6 +5,7 @@
 #include "ansi-color.h"
 #include "bus-error.h"
 #include "bus-locator.h"
+#include "bus-message-util.h"
 #include "format-table.h"
 #include "locale-util.h"
 #include "path-util.h"
index c79bb864df0e5bda56a4db94f7df420ce3856d5f..b196034a2524a5f726248f9c89a743d83b521a5e 100644 (file)
@@ -17,6 +17,7 @@
 #include "bus-locator.h"
 #include "bus-log-control-api.h"
 #include "bus-map-properties.h"
+#include "bus-message-util.h"
 #include "bus-polkit.h"
 #include "bus-unit-util.h"
 #include "clock-util.h"