return 0;
}
-static int enqueue_kernel_reply(
- sd_bus *bus,
- sd_bus_slot **ret_slot,
- int reply,
- sd_bus_message_handler_t callback,
- void *userdata,
- const char *error_failed_message)
+static int prepare_int_reply(sd_bus *bus,
+ sd_bus_message **ret_m,
+ int reply,
+ const char *error_failed_message)
{
int ret;
- _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *s = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
uint64_t cookie;
if (ret < 0)
return ret;
+ *ret_m = m;
+ m = NULL;
+ return 0;
+}
+
+static int enqueue_kernel_reply(
+ sd_bus *bus,
+ sd_bus_slot **ret_slot,
+ sd_bus_message *m,
+ sd_bus_message_handler_t callback,
+ void *userdata)
+{
+ int ret;
+ _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *s = NULL;
+
if (ret_slot || callback) {
s = bus_slot_allocate(bus, !ret_slot, BUS_REPLY_CALLBACK, sizeof(struct reply_callback), userdata);
if (!s)
s->reply_callback.callback = callback;
- s->reply_callback.cookie = cookie;
+ s->reply_callback.cookie = bus->cookie;
ret = ordered_hashmap_put(bus->reply_callbacks, &s->reply_callback.cookie, &s->reply_callback);
if (ret < 0) {
s->reply_callback.cookie = 0;
}
bus->rqueue[bus->rqueue_size++] = m;
- m = NULL;
if (ret_slot)
*ret_slot = s;
return 0;
}
+static int enqueue_int_kernel_reply(
+ sd_bus *bus,
+ sd_bus_slot **ret_slot,
+ int reply,
+ const char *error_string,
+ sd_bus_message_handler_t callback,
+ void *userdata) {
+ int ret;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+
+ ret = prepare_int_reply(bus, &m, reply, error_string);
+ if (ret < 0)
+ return ret;
+
+ ret = enqueue_kernel_reply(bus, ret_slot, m, callback, userdata);
+ if (ret < 0)
+ return ret;
+
+ m = NULL;
+ return 1;
+}
+
int bus_request_name_kernel_async(sd_bus *bus,
sd_bus_slot **ret_slot,
const char *name,
if (ret < 0)
return ret;
- ret = bus_request_name_kernel(bus, name, flags);
-
- return enqueue_kernel_reply(bus, ret_slot, ret, callback, userdata, "Request name failed");
+ return enqueue_int_kernel_reply(bus,
+ ret_slot,
+ bus_request_name_kernel(bus, name, flags),
+ "Request name failed",
+ callback,
+ userdata);
}
int bus_release_name_kernel(sd_bus *bus, const char *name) {
if (ret < 0)
return ret;
- ret = bus_release_name_kernel(bus, name);
-
- return enqueue_kernel_reply(bus, ret_slot, ret, callback, userdata, "Release name failed");
+ return enqueue_int_kernel_reply(bus,
+ ret_slot,
+ bus_release_name_kernel(bus, name),
+ "Release name failed",
+ callback,
+ userdata);
}
-
static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
struct kdbus_cmd_list cmd = {
.size = sizeof(cmd),