X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibelogind%2Fsd-bus%2Fsd-bus.c;h=54f3977307acc16e0980de72fc9b49c6040b6adc;hb=9a81bd550c4c0c7bced561fdae2dc4c6780ff820;hp=35de5b051e93dee908a56717eb27a5a95a04800b;hpb=162255186046fa7a5e82859b7dba5a7909ce6fc4;p=elogind.git diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c index 35de5b051..54f397730 100644 --- a/src/libelogind/sd-bus/sd-bus.c +++ b/src/libelogind/sd-bus/sd-bus.c @@ -367,13 +367,15 @@ _public_ int sd_bus_get_allow_interactive_authorization(sd_bus *bus) { return bus->allow_interactive_authorization; } -static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) { +static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *error) { const char *s; + sd_bus *bus; int r; + assert(reply); + bus = reply->bus; assert(bus); assert(bus->state == BUS_HELLO || bus->state == BUS_CLOSING); - assert(reply); r = sd_bus_message_get_errno(reply); if (r > 0) @@ -1690,8 +1692,11 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, _cleanup_bus_message_unref_ sd_bus_message *m = sd_bus_message_ref(_m); int r; - assert_return(bus, -EINVAL); assert_return(m, -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); @@ -1776,8 +1781,11 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *cookie) { _public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *cookie) { int r; - assert_return(bus, -EINVAL); assert_return(m, -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); if (!BUS_IS_OPEN(bus->state)) @@ -1833,11 +1841,14 @@ _public_ int sd_bus_call_async( _cleanup_bus_slot_unref_ sd_bus_slot *s = NULL; int r; - assert_return(bus, -EINVAL); assert_return(m, -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(callback, -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); @@ -1931,11 +1942,14 @@ _public_ int sd_bus_call( unsigned i; int r; - assert_return(bus, -EINVAL); assert_return(m, -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(!bus_error_is_dirty(error), -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); @@ -2190,7 +2204,7 @@ static int process_timeout(sd_bus *bus) { bus->current_slot = sd_bus_slot_ref(slot); bus->current_handler = c->callback; bus->current_userdata = slot->userdata; - r = c->callback(bus, m, slot->userdata, &error_buffer); + r = c->callback(m, slot->userdata, &error_buffer); bus->current_userdata = NULL; bus->current_handler = NULL; bus->current_slot = NULL; @@ -2293,7 +2307,7 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) { bus->current_slot = sd_bus_slot_ref(slot); bus->current_handler = c->callback; bus->current_userdata = slot->userdata; - r = c->callback(bus, m, slot->userdata, &error_buffer); + r = c->callback(m, slot->userdata, &error_buffer); bus->current_userdata = NULL; bus->current_handler = NULL; bus->current_slot = NULL; @@ -2340,7 +2354,7 @@ static int process_filter(sd_bus *bus, sd_bus_message *m) { bus->current_slot = sd_bus_slot_ref(slot); bus->current_handler = l->callback; bus->current_userdata = slot->userdata; - r = l->callback(bus, m, slot->userdata, &error_buffer); + r = l->callback(m, slot->userdata, &error_buffer); bus->current_userdata = NULL; bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); @@ -2621,7 +2635,7 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) { bus->current_slot = sd_bus_slot_ref(slot); bus->current_handler = c->callback; bus->current_userdata = slot->userdata; - r = c->callback(bus, m, slot->userdata, &error_buffer); + r = c->callback(m, slot->userdata, &error_buffer); bus->current_userdata = NULL; bus->current_handler = NULL; bus->current_slot = NULL; @@ -3493,7 +3507,7 @@ _public_ int sd_bus_get_address(sd_bus *bus, const char **address) { return -ENODATA; } -int sd_bus_get_creds_mask(sd_bus *bus, uint64_t *mask) { +_public_ int sd_bus_get_creds_mask(sd_bus *bus, uint64_t *mask) { assert_return(bus, -EINVAL); assert_return(mask, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); @@ -3502,35 +3516,35 @@ int sd_bus_get_creds_mask(sd_bus *bus, uint64_t *mask) { return 0; } -int sd_bus_is_bus_client(sd_bus *bus) { +_public_ int sd_bus_is_bus_client(sd_bus *bus) { assert_return(bus, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); return bus->bus_client; } -int sd_bus_is_server(sd_bus *bus) { +_public_ int sd_bus_is_server(sd_bus *bus) { assert_return(bus, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); return bus->is_server; } -int sd_bus_is_anonymous(sd_bus *bus) { +_public_ int sd_bus_is_anonymous(sd_bus *bus) { assert_return(bus, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); return bus->anonymous_auth; } -int sd_bus_is_trusted(sd_bus *bus) { +_public_ int sd_bus_is_trusted(sd_bus *bus) { assert_return(bus, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); return bus->trusted; } -int sd_bus_is_monitor(sd_bus *bus) { +_public_ int sd_bus_is_monitor(sd_bus *bus) { assert_return(bus, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD);