From: Lennart Poettering Date: Fri, 11 Oct 2013 17:33:39 +0000 (+0200) Subject: bus: automatically do a NOP reply when a NULL callback is specified for a method... X-Git-Tag: v209~1925 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=43a43f5016eb9404afdd6719b18f604a484535ec bus: automatically do a NOP reply when a NULL callback is specified for a method in a vtable Also, allow specifiying NULL as signature in vtables equivalent to "" for empty parameter lists. --- diff --git a/TODO b/TODO index 4a4746370..6847217cb 100644 --- a/TODO +++ b/TODO @@ -182,9 +182,7 @@ Features: - merge busctl into systemctl or so? - synthesize sd_bus_message objects from kernel messages - properly implement name registry ioctls for kdbus - - get rid of object hash table, use decision tree everyhwere instead? - implement monitor logic - - object vtable logic - longer term: * priority queues * priority inheritance diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 1d8d56942..3fd518676 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -2100,7 +2100,15 @@ static int method_callbacks_run( return 1; } - return c->vtable->method.handler(bus, m, u); + if (c->vtable->method.handler) + return c->vtable->method.handler(bus, m, u); + + /* If the method callback is NULL, make this a successful NOP */ + r = sd_bus_reply_method_return(bus, m, NULL); + if (r < 0) + return r; + + return 1; } static int invoke_property_get( @@ -3761,7 +3769,7 @@ static int add_object_vtable_internal( if (!member_name_is_valid(v->method.member) || !signature_is_valid(v->method.signature, false) || !signature_is_valid(v->method.result, false) || - !v->method.handler || + !(v->method.handler || (isempty(v->method.signature) && isempty(v->method.result))) || v->flags & (SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE|SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY)) { r = -EINVAL; goto fail; diff --git a/src/libsystemd-bus/test-bus-objects.c b/src/libsystemd-bus/test-bus-objects.c index 06947a2c1..637e0511b 100644 --- a/src/libsystemd-bus/test-bus-objects.c +++ b/src/libsystemd-bus/test-bus-objects.c @@ -39,8 +39,6 @@ * Add in: * * automatic properties for Set() - * automatic NULL method - * allow NULL as signatures in vtable * node hierarchy updates during dispatching * emit_interfaces_added/emit_interfaces_removed * @@ -157,6 +155,7 @@ static const sd_bus_vtable vtable[] = { SD_BUS_WRITABLE_PROPERTY("Something", "s", get_handler, set_handler, 0, 0), SD_BUS_PROPERTY("AutomaticStringProperty", "s", NULL, offsetof(struct context, automatic_string_property), 0), SD_BUS_PROPERTY("AutomaticIntegerProperty", "u", NULL, offsetof(struct context, automatic_integer_property), 0), + SD_BUS_METHOD("NoOperation", "", "", NULL, 0), SD_BUS_VTABLE_END }; @@ -241,6 +240,9 @@ static int client(struct context *c) { assert_se(sd_bus_set_fd(bus, c->fds[1], c->fds[1]) >= 0); assert_se(sd_bus_start(bus) >= 0); + r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "NoOperation", &error, NULL, NULL); + assert_se(r >= 0); + r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "AlterSomething", &error, &reply, "s", "hallo"); assert_se(r >= 0);