1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 16:21:26 +03:00

sd-bus: accept NULL callbacks in sd_bus_call_async()

This way sd_bus_call_method_async() (which is just a wrapper around
sd_bus_call_async()) can be used to put method calls together that
expect no reply.
This commit is contained in:
Lennart Poettering 2017-12-20 19:45:09 +01:00
parent 3e0e196efd
commit dbc526f0bc

View File

@ -1871,8 +1871,7 @@ _public_ int sd_bus_call_async(
assert_return(m, -EINVAL); assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL); assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); assert_return(!m->sealed || (!!callback == !(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)), -EINVAL);
assert_return(callback, -EINVAL);
if (!bus) if (!bus)
bus = m->bus; bus = m->bus;
@ -1882,6 +1881,10 @@ _public_ int sd_bus_call_async(
if (!BUS_IS_OPEN(bus->state)) if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN; return -ENOTCONN;
/* If no callback is specified and there's no interest in a slot, then there's no reason to ask for a reply */
if (!callback && !slot && !m->sealed)
m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
r = ordered_hashmap_ensure_allocated(&bus->reply_callbacks, &uint64_hash_ops); r = ordered_hashmap_ensure_allocated(&bus->reply_callbacks, &uint64_hash_ops);
if (r < 0) if (r < 0)
return r; return r;
@ -1898,6 +1901,7 @@ _public_ int sd_bus_call_async(
if (r < 0) if (r < 0)
return r; return r;
if (slot || callback) {
s = bus_slot_allocate(bus, !slot, BUS_REPLY_CALLBACK, sizeof(struct reply_callback), userdata); s = bus_slot_allocate(bus, !slot, BUS_REPLY_CALLBACK, sizeof(struct reply_callback), userdata);
if (!s) if (!s)
return -ENOMEM; return -ENOMEM;
@ -1919,8 +1923,9 @@ _public_ int sd_bus_call_async(
return r; return r;
} }
} }
}
r = sd_bus_send(bus, m, &s->reply_callback.cookie); r = sd_bus_send(bus, m, s ? &s->reply_callback.cookie : NULL);
if (r < 0) if (r < 0)
return r; return r;