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.
This commit is contained in:
Lennart Poettering 2013-10-11 19:33:39 +02:00
parent 1a0464230c
commit 43a43f5016
3 changed files with 14 additions and 6 deletions

2
TODO
View File

@ -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

View File

@ -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;

View File

@ -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);