resource: improve error handling

Make some more varargs error functions
Make pw_resource_error always just send the error to the resource id.
Make sure we send errors to the right destination.
Add proxy error event and emit it when the core finds an error for
the given proxy id.
The client error is supposed to be sent to all resources of a client
for the given global.
This commit is contained in:
Wim Taymans 2019-02-14 16:53:42 +01:00
parent cbdc024f4c
commit 8ae5424359
17 changed files with 107 additions and 64 deletions

View file

@ -174,7 +174,7 @@ core_check_access(void *data, struct pw_client *client)
return;
blacklisted:
pw_resource_error(pw_client_get_core_resource(client), 0, res, "blacklisted");
pw_resource_error(pw_client_get_core_resource(client), res, "blacklisted");
pw_client_update_properties(client, &SPA_DICT_INIT(items, 1));
return;

View file

@ -154,18 +154,18 @@ static void *create_object(void *_data,
no_resource:
pw_log_error("audio-dsp needs a resource");
pw_resource_error(resource, new_id, -EINVAL, "no resource");
pw_resource_error(resource, -EINVAL, "no resource");
goto done;
no_props:
pw_log_error("audio-dsp needs a property");
pw_resource_error(resource, new_id, -EINVAL, "no property");
pw_resource_error(resource, -EINVAL, "no property");
goto done;
no_mem:
pw_log_error("can't create node");
pw_resource_error(resource, new_id, -ENOMEM, "no memory");
pw_resource_error(resource, -ENOMEM, "no memory");
goto done;
no_bind:
pw_resource_error(resource, new_id, res, "can't bind dsp node");
pw_resource_error(resource, res, "can't bind dsp node");
goto done;
done:
if (properties)

View file

@ -89,7 +89,7 @@ static void *create_object(void *_data,
no_mem:
pw_log_error("can't create node");
pw_resource_error(resource, new_id, -ENOMEM, "no memory");
pw_core_resource_error(pw_client_get_core_resource(client), new_id, -ENOMEM, "can't create node: no memory");
goto done;
done:
if (properties)

View file

@ -246,30 +246,30 @@ static void *create_object(void *_data,
no_properties:
pw_log_error("link-factory needs properties");
pw_resource_error(resource, new_id, -EINVAL, "no properties");
pw_resource_error(resource, -EINVAL, "no properties");
goto done;
no_output:
pw_log_error("link-factory unknown output node %d", output_node_id);
pw_resource_error(resource, new_id, -EINVAL, "unknown output node");
pw_log_error("link-factory unknown output node %u", output_node_id);
pw_resource_error(resource, -EINVAL, "unknown output node %u", output_node_id);
goto done;
no_input:
pw_log_error("link-factory unknown input node %d", input_node_id);
pw_resource_error(resource, new_id, -EINVAL, "unknown input node");
pw_log_error("link-factory unknown input node %u", input_node_id);
pw_resource_error(resource, -EINVAL, "unknown input node %u", input_node_id);
goto done;
no_output_port:
pw_log_error("link-factory unknown output port %d", output_port_id);
pw_resource_error(resource, new_id, -EINVAL, "unknown output port");
pw_log_error("link-factory unknown output port %u", output_port_id);
pw_resource_error(resource, -EINVAL, "unknown output port %u", output_port_id);
goto done;
no_input_port:
pw_log_error("link-factory unknown input port %d", input_port_id);
pw_resource_error(resource, new_id, -EINVAL, "unknown input port");
pw_log_error("link-factory unknown input port %u", input_port_id);
pw_resource_error(resource, -EINVAL, "unknown input port %u", input_port_id);
goto done;
no_mem:
pw_log_error("can't create link: %s", error);
pw_resource_error(resource, new_id, -ENOMEM, error);
pw_resource_error(resource, -ENOMEM, "can't create link: %s", error);
goto done;
no_bind:
pw_resource_error(resource, new_id, res, "can't bind link");
pw_resource_error(resource, res, "can't bind link");
goto done;
done:
if (properties)

View file

@ -117,13 +117,13 @@ process_messages(struct client_data *data)
uint8_t opcode;
uint32_t id, size;
void *message;
struct pw_resource *resource;
core->current_client = client;
/* when the client is busy processing an async action, stop processing messages
* for the client until it finishes the action */
while (!data->busy) {
struct pw_resource *resource;
const struct pw_protocol_native_demarshal *demarshal;
const struct pw_protocol_marshal *marshal;
uint32_t permissions, required;
@ -143,7 +143,7 @@ process_messages(struct client_data *data)
if (resource == NULL) {
pw_log_error("protocol-native %p: unknown resource %u",
client->protocol, id);
pw_core_resource_error(client->core_resource, id,
pw_resource_error(client->core_resource,
-EINVAL, "unknown resource %u", id);
continue;
}
@ -162,7 +162,7 @@ process_messages(struct client_data *data)
if ((required & permissions) != required) {
pw_log_error("protocol-native %p: method %u on %u requires %08x, have %08x",
client->protocol, opcode, id, required, permissions);
pw_core_resource_error(client->core_resource, id,
pw_resource_error(resource,
-EACCES, "no permission to call method %u ", opcode, id);
continue;
}
@ -177,15 +177,13 @@ process_messages(struct client_data *data)
invalid_method:
pw_log_error("protocol-native %p: invalid method %u on resource %u",
client->protocol, opcode, id);
pw_core_resource_error(client->core_resource, id,
-EINVAL, "invalid method %u on resource %u", opcode, id);
pw_resource_error(resource, -EINVAL, "invalid method %u", opcode);
pw_client_destroy(client);
goto done;
invalid_message:
pw_log_error("protocol-native %p: invalid message received %u %u",
client->protocol, id, opcode);
pw_core_resource_error(client->core_resource, id,
-EINVAL, "invalid message %u %u", opcode, id);
pw_resource_error(resource, -EINVAL, "invalid message %u", opcode);
spa_debug_pod(0, NULL, (struct spa_pod *)message);
pw_client_destroy(client);
goto done;

View file

@ -252,23 +252,17 @@ static void core_marshal_done(void *object, uint32_t seq)
pw_protocol_native_end_resource(resource, b);
}
static void core_marshal_error(void *object, uint32_t id, int res, const char *error, ...)
static void core_marshal_error(void *object, uint32_t id, int res, const char *error)
{
struct pw_resource *resource = object;
char buffer[128];
struct spa_pod_builder *b;
va_list ap;
b = pw_protocol_native_begin_resource(resource, PW_CORE_PROXY_EVENT_ERROR);
va_start(ap, error);
vsnprintf(buffer, sizeof(buffer), error, ap);
va_end(ap);
spa_pod_builder_add_struct(b,
SPA_POD_Int(id),
SPA_POD_Int(res),
SPA_POD_String(buffer));
SPA_POD_String(error));
pw_protocol_native_end_resource(resource, b);
}

View file

@ -122,16 +122,16 @@ static void *create_object(void *_data,
no_properties:
pw_log_error("needed properties: spa.library.name=<library-name> spa.factory.name=<factory-name>");
if (resource) {
pw_resource_error(resource, new_id, -EINVAL,
pw_resource_error(resource, -EINVAL,
"needed properties: "
"spa.library.name=<library-name> "
"spa.factory.name=<factory-name>");
}
return NULL;
no_mem:
pw_log_error("can't create node");
pw_log_error("can't create node: no memory");
if (resource) {
pw_resource_error(resource, new_id, -ENOMEM, "no memory");
pw_resource_error(resource, -ENOMEM, "no memory");
}
return NULL;
}