sd-bus: kdbus: fix callbacks for matches sandbox/adrians/upgrade-to-237
authorAdrian Szyndela <adrian.s@samsung.com>
Mon, 23 Mar 2020 15:39:04 +0000 (16:39 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Thu, 26 Mar 2020 14:43:36 +0000 (15:43 +0100)
Add callbacks for matches to reply_callbacks to perform
them after processing synchronous response to asynchronous
calls to AddMatch.

src/libsystemd/sd-bus/bus-control-kernel.c
src/libsystemd/sd-bus/bus-slot.c

index 6242641..bfd38a4 100644 (file)
@@ -180,7 +180,7 @@ static int enqueue_kernel_reply(
 
         s->reply_callback.callback = callback;
 
-        s->reply_callback.cookie = bus->cookie;
+        s->reply_callback.cookie = m->reply_cookie;
         ret = ordered_hashmap_put(bus->reply_callbacks, &s->reply_callback.cookie, &s->reply_callback);
         if (ret < 0) {
             s->reply_callback.cookie = 0;
@@ -1231,27 +1231,22 @@ int bus_add_match_internal_kernel_async(
 {
     int ret;
     _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+    uint64_t reply_cookie;
 
-    /* we want room for the return message */
-    ret = bus_rqueue_make_room(bus);
+    ret = prepare_for_kernel_request(bus);
     if (ret < 0)
         return ret;
 
-    if (NULL != ret_slot) {
-        *ret_slot = bus_slot_allocate(bus, false, BUS_KDBUS_CALLBACK, 0, NULL);
-        if (!(*ret_slot))
-            return -ENOMEM;
-    }
-
     ret = bus_add_match_internal_kernel(bus, components, n_components, cookie);
 
+    reply_cookie = ++bus->cookie;
     if (ret < 0) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
 
         sd_bus_error_setf(&error, SD_BUS_ERROR_FAILED, "Add match failed");
-        ret = bus_message_new_synthetic_error(bus, cookie, &error, &m);
+        ret = bus_message_new_synthetic_error(bus, reply_cookie, &error, &m);
     } else
-        ret = bus_message_new_synthetic_reply(bus, cookie, &m);
+        ret = bus_message_new_synthetic_reply(bus, reply_cookie, &m);
 
     if (ret < 0)
         return ret;
@@ -1260,7 +1255,7 @@ int bus_add_match_internal_kernel_async(
     if (ret < 0)
         return ret;
 
-    bus->rqueue[bus->rqueue_size++] = m;
+    ret = enqueue_kernel_reply(bus, ret_slot, m, callback, userdata);
     m = NULL;
 
     return ret;
index 28c6b1d..7fd5368 100644 (file)
@@ -76,8 +76,6 @@ void bus_slot_disconnect(sd_bus_slot *slot) {
 
         switch (slot->type) {
 
-        case BUS_KDBUS_CALLBACK:
-                break;
         case BUS_REPLY_CALLBACK:
 
                 if (slot->reply_callback.cookie != 0)