sd_bus *bus,
const char *path,
struct node_vtable *c,
- void **userdata) {
+ void **userdata,
+ sd_bus_error *error) {
void *u;
int r;
u = c->userdata;
if (c->find) {
- r = c->find(bus, path, c->interface, &u, u);
- if (r <= 0)
+ r = c->find(bus, path, c->interface, u, &u, error);
+ if (r < 0)
+ return r;
+ if (sd_bus_error_is_set(error))
+ return sd_bus_error_get_errno(error);
+ if (r == 0)
return r;
}
sd_bus *bus,
const char *path,
struct vtable_member *p,
- void **userdata) {
+ void **userdata,
+ sd_bus_error *error) {
void *u;
int r;
assert(p);
assert(userdata);
- r = node_vtable_get_userdata(bus, path, p->parent, &u);
+ r = node_vtable_get_userdata(bus, path, p->parent, &u, error);
if (r <= 0)
return r;
if (bus->nodes_modified)
sd_bus *bus,
const char *prefix,
struct node_enumerator *first,
- Set *s) {
+ Set *s,
+ sd_bus_error *error) {
struct node_enumerator *c;
int r;
if (bus->nodes_modified)
return 0;
- r = c->callback(bus, prefix, &children, c->userdata);
+ r = c->callback(bus, prefix, c->userdata, &children, error);
if (r < 0)
return r;
+ if (sd_bus_error_is_set(error))
+ return sd_bus_error_get_errno(error);
STRV_FOREACH(k, children) {
if (r < 0) {
}
r = set_consume(s, *k);
+ if (r == -EEXIST)
+ r = 0;
}
free(children);
sd_bus *bus,
const char *prefix,
struct node *n,
- Set *s) {
+ Set *s,
+ sd_bus_error *error) {
struct node *i;
int r;
assert(n);
assert(s);
- r = add_enumerated_to_set(bus, prefix, n->enumerators, s);
+ r = add_enumerated_to_set(bus, prefix, n->enumerators, s, error);
if (r < 0)
return r;
if (bus->nodes_modified)
if (r < 0 && r != -EEXIST)
return r;
- r = add_subtree_to_set(bus, prefix, i, s);
+ r = add_subtree_to_set(bus, prefix, i, s, error);
if (r < 0)
return r;
if (bus->nodes_modified)
sd_bus *bus,
const char *prefix,
struct node *n,
- Set **_s) {
+ Set **_s,
+ sd_bus_error *error) {
Set *s = NULL;
int r;
if (!s)
return -ENOMEM;
- r = add_subtree_to_set(bus, prefix, n, s);
+ r = add_subtree_to_set(bus, prefix, n, s, error);
if (r < 0) {
set_free_free(s);
return r;
assert(found_object);
LIST_FOREACH(callbacks, c, first) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
if (bus->nodes_modified)
return 0;
if (r < 0)
return r;
- r = c->callback(bus, m, c->userdata);
+ r = c->callback(bus, m, c->userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
if (r != 0)
return r;
}
bool require_fallback,
bool *found_object) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
const char *signature;
void *u;
int r;
if (require_fallback && !c->parent->is_fallback)
return 0;
- r = node_vtable_get_userdata(bus, m->path, c->parent, &u);
+ r = node_vtable_get_userdata(bus, m->path, c->parent, &u, &error);
if (r <= 0)
- return r;
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
if (!signature)
return -EINVAL;
- if (!streq(strempty(c->vtable->x.method.signature), signature)) {
- r = sd_bus_reply_method_errorf(m,
- SD_BUS_ERROR_INVALID_ARGS,
- "Invalid arguments '%s' to call %s:%s, expecting '%s'.",
- signature, c->interface, c->member, strempty(c->vtable->x.method.signature));
- if (r < 0)
- return r;
-
- return 1;
+ if (!streq(strempty(c->vtable->x.method.signature), signature))
+ return sd_bus_reply_method_errorf(
+ m,
+ SD_BUS_ERROR_INVALID_ARGS,
+ "Invalid arguments '%s' to call %s.%s(), expecting '%s'.",
+ signature, c->interface, c->member, strempty(c->vtable->x.method.signature));
+
+ /* Keep track what the signature of the reply to this message
+ * should be, so that this can be enforced when sealing the
+ * reply. */
+ m->enforced_reply_signature = strempty(c->vtable->x.method.result);
+
+ if (c->vtable->x.method.handler) {
+ r = c->vtable->x.method.handler(bus, m, u, &error);
+ return bus_maybe_reply_error(m, r, &error);
}
- if (c->vtable->x.method.handler)
- return c->vtable->x.method.handler(bus, m, u);
-
/* If the method callback is NULL, make this a successful NOP */
r = sd_bus_reply_method_return(m, NULL);
if (r < 0)
const char *path,
const char *interface,
const char *property,
- sd_bus_message *m,
- sd_bus_error *error,
- void *userdata) {
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
const void *p;
+ int r;
assert(bus);
assert(v);
assert(path);
assert(interface);
assert(property);
- assert(m);
+ assert(reply);
- if (v->x.property.get)
- return v->x.property.get(bus, path, interface, property, m, error, userdata);
+ if (v->x.property.get) {
+ r = v->x.property.get(bus, path, interface, property, reply, userdata, error);
+ if (r < 0)
+ return r;
+ if (sd_bus_error_is_set(error))
+ return sd_bus_error_get_errno(error);
+ return r;
+ }
/* Automatic handling if no callback is defined. */
if (streq(v->x.property.signature, "as"))
- return sd_bus_message_append_strv(m, *(char***) userdata);
+ return sd_bus_message_append_strv(reply, *(char***) userdata);
assert(signature_is_single(v->x.property.signature, false));
assert(bus_type_is_basic(v->x.property.signature[0]));
break;
}
- return sd_bus_message_append_basic(m, v->x.property.signature[0], p);
+ return sd_bus_message_append_basic(reply, v->x.property.signature[0], p);
}
static int invoke_property_set(
const char *interface,
const char *property,
sd_bus_message *value,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
int r;
assert(property);
assert(value);
- if (v->x.property.set)
- return v->x.property.set(bus, path, interface, property, value, error, userdata);
+ if (v->x.property.set) {
+ r = v->x.property.set(bus, path, interface, property, value, userdata, error);
+ if (r < 0)
+ return r;
+ if (sd_bus_error_is_set(error))
+ return sd_bus_error_get_errno(error);
+ return r;
+ }
/* Automatic handling if no callback is defined. */
bool is_get,
bool *found_object) {
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
void *u;
int r;
if (require_fallback && !c->parent->is_fallback)
return 0;
- r = vtable_property_get_userdata(bus, m->path, c, &u);
+ r = vtable_property_get_userdata(bus, m->path, c, &u, &error);
if (r <= 0)
- return r;
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
if (r < 0)
return r;
- r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, &error, u);
+ r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, u, &error);
if (r < 0)
- return r;
-
- if (sd_bus_error_is_set(&error)) {
- r = sd_bus_reply_method_error(m, &error);
- if (r < 0)
- return r;
-
- return 1;
- }
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
} else {
if (c->vtable->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
- sd_bus_error_setf(&error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Property '%s' is not writable.", c->member);
- else {
- /* Avoid that we call the set routine more
- * than once if the processing of this message
- * got restarted because the node tree
- * changed. */
- if (c->last_iteration == bus->iteration_counter)
- return 0;
-
- c->last_iteration = bus->iteration_counter;
+ return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Property '%s' is not writable.", c->member);
- r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature);
- if (r < 0)
- return r;
+ /* Avoid that we call the set routine more than once
+ * if the processing of this message got restarted
+ * because the node tree changed. */
+ if (c->last_iteration == bus->iteration_counter)
+ return 0;
- r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, &error, u);
- if (r < 0)
- return r;
- }
+ c->last_iteration = bus->iteration_counter;
- if (sd_bus_error_is_set(&error)) {
- r = sd_bus_reply_method_error(m, &error);
- if (r < 0)
- return r;
+ r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature);
+ if (r < 0)
+ return r;
- return 1;
- }
+ r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, u, &error);
+ if (r < 0)
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
if (r < 0)
return r;
- r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, error, vtable_property_convert_userdata(v, userdata));
+ r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, vtable_property_convert_userdata(v, userdata), error);
if (r < 0)
return r;
- if (sd_bus_error_is_set(error))
- return 0;
if (bus->nodes_modified)
return 0;
if (require_fallback && !c->is_fallback)
continue;
- r = node_vtable_get_userdata(bus, m->path, c, &u);
+ r = node_vtable_get_userdata(bus, m->path, c, &u, &error);
if (r < 0)
- return r;
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
if (r == 0)
r = vtable_append_all_properties(bus, reply, m->path, c, u, &error);
if (r < 0)
- return r;
-
- if (sd_bus_error_is_set(&error)) {
- r = sd_bus_reply_method_error(m, &error);
- if (r < 0)
- return r;
-
- return 1;
- }
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
}
}
LIST_FOREACH(vtables, c, n->vtables) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
if (require_fallback && !c->is_fallback)
continue;
- if (node_vtable_get_userdata(bus, path, c, NULL) > 0)
+ if (node_vtable_get_userdata(bus, path, c, NULL, &error) > 0)
return true;
if (bus->nodes_modified)
return false;
bool require_fallback,
bool *found_object) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_set_free_free_ Set *s = NULL;
const char *previous_interface = NULL;
assert(n);
assert(found_object);
- r = get_child_nodes(bus, m->path, n, &s);
+ r = get_child_nodes(bus, m->path, n, &s, &error);
if (r < 0)
- return r;
+ return bus_maybe_reply_error(m, r, &error);
if (bus->nodes_modified)
return 0;
if (require_fallback && !c->is_fallback)
continue;
- r = node_vtable_get_userdata(bus, m->path, c, NULL);
- if (r < 0)
- return r;
- if (bus->nodes_modified)
- return 0;
+ r = node_vtable_get_userdata(bus, m->path, c, NULL, &error);
+ if (r < 0) {
+ r = bus_maybe_reply_error(m, r, &error);
+ goto finish;
+ }
+ if (bus->nodes_modified) {
+ r = 0;
+ goto finish;
+ }
if (r == 0)
continue;
if (require_fallback && !i->is_fallback)
continue;
- r = node_vtable_get_userdata(bus, path, i, &u);
+ r = node_vtable_get_userdata(bus, path, i, &u, error);
if (r < 0)
return r;
if (bus->nodes_modified)
r = vtable_append_all_properties(bus, reply, path, i, u, error);
if (r < 0)
return r;
- if (sd_bus_error_is_set(error))
- return 0;
if (bus->nodes_modified)
return 0;
r = object_manager_serialize_path(bus, reply, path, path, false, error);
if (r < 0)
return r;
- if (sd_bus_error_is_set(error))
- return 0;
if (bus->nodes_modified)
return 0;
r = object_manager_serialize_path(bus, reply, prefix, path, true, error);
if (r < 0)
return r;
- if (sd_bus_error_is_set(error))
- return 0;
if (bus->nodes_modified)
return 0;
}
bool require_fallback,
bool *found_object) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_set_free_free_ Set *s = NULL;
bool empty;
if (!bus_node_with_object_manager(bus, n))
return 0;
- r = get_child_nodes(bus, m->path, n, &s);
+ r = get_child_nodes(bus, m->path, n, &s, &error);
if (r < 0)
return r;
if (bus->nodes_modified)
char *path;
SET_FOREACH(path, s, i) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-
r = object_manager_serialize_path_and_fallbacks(bus, reply, path, &error);
if (r < 0)
- return -ENOMEM;
-
- if (sd_bus_error_is_set(&error)) {
- r = sd_bus_reply_method_error(m, &error);
- if (r < 0)
- return r;
-
- return 1;
- }
+ return r;
if (bus->nodes_modified)
return 0;
r = sd_bus_message_read(m, "ss", &vtable_key.interface, &vtable_key.member);
if (r < 0)
- return r;
+ return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected interface and member parameters");
v = hashmap_get(bus->vtable_properties, &vtable_key);
if (v) {
r = sd_bus_message_read(m, "s", &iface);
if (r < 0)
- return r;
+ return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected interface parameter");
if (iface[0] == 0)
iface = NULL;
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+ if (!isempty(sd_bus_message_get_signature(m, true)))
+ return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected no parameters");
+
r = process_introspect(bus, m, n, require_fallback, found_object);
if (r != 0)
return r;
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects")) {
+ if (!isempty(sd_bus_message_get_signature(m, true)))
+ return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected no parameters");
+
r = process_get_managed_objects(bus, m, n, require_fallback, found_object);
if (r != 0)
return r;
bool require_fallback,
char **names) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
bool has_invalidating = false, has_changing = false;
struct vtable_member key = {};
if (!streq(c->interface, interface))
continue;
- r = node_vtable_get_userdata(bus, path, c, &u);
+ r = node_vtable_get_userdata(bus, path, c, &u, &error);
if (r < 0)
return r;
if (bus->nodes_modified)
continue;
STRV_FOREACH(property, names) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
struct vtable_member *v;
assert_return(member_name_is_valid(*property), -EINVAL);
if (r < 0)
return r;
- r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, &error, vtable_property_convert_userdata(v->vtable, u));
+ r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, vtable_property_convert_userdata(v->vtable, u), &error);
if (r < 0)
return r;
if (bus->nodes_modified)
if (!streq(c->interface, interface))
continue;
- r = node_vtable_get_userdata(bus, path, c, &u);
+ r = node_vtable_get_userdata(bus, path, c, &u, &error);
if (r < 0)
return r;
if (bus->nodes_modified)
if (!streq(c->interface, interface))
continue;
- r = node_vtable_get_userdata(bus, path, c, &u);
+ r = node_vtable_get_userdata(bus, path, c, &u, &error);
if (r < 0)
return r;
if (bus->nodes_modified)