improve error handling some more

This commit is contained in:
Wim Taymans 2019-06-20 11:04:34 +02:00
parent d1241e2c1c
commit a212d2f9ed
30 changed files with 393 additions and 312 deletions

View file

@ -170,24 +170,22 @@ core_check_access(void *data, struct pw_client *client)
goto wait_permissions; goto wait_permissions;
} }
granted: granted:
pw_log_debug("module %p: client %p access granted", impl, client); pw_log_debug("module %p: client %p access granted", impl, client);
permissions[0] = PW_PERMISSION_INIT(-1, PW_PERM_RWX); permissions[0] = PW_PERMISSION_INIT(-1, PW_PERM_RWX);
pw_client_update_permissions(client, 1, permissions); pw_client_update_permissions(client, 1, permissions);
return; return;
wait_permissions: wait_permissions:
pw_log_debug("module %p: client %p wait for permissions", impl, client); pw_log_debug("module %p: client %p wait for permissions", impl, client);
pw_client_update_properties(client, &SPA_DICT_INIT(items, 1)); pw_client_update_properties(client, &SPA_DICT_INIT(items, 1));
pw_client_set_busy(client, true); pw_client_set_busy(client, true);
return; return;
blacklisted: blacklisted:
pw_resource_error(pw_client_get_core_resource(client), res, "blacklisted"); pw_resource_error(pw_client_get_core_resource(client), res, "blacklisted");
pw_client_update_properties(client, &SPA_DICT_INIT(items, 1)); pw_client_update_properties(client, &SPA_DICT_INIT(items, 1));
return; return;
} }
static const struct pw_core_events core_events = { static const struct pw_core_events core_events = {

View file

@ -47,7 +47,6 @@ static const struct spa_dict_item module_props[] = {
struct factory_data { struct factory_data {
struct pw_factory *this; struct pw_factory *this;
struct pw_properties *properties;
struct spa_list node_list; struct spa_list node_list;
@ -103,19 +102,20 @@ static void *create_object(void *_data,
struct pw_resource *bound_resource; struct pw_resource *bound_resource;
if (resource == NULL) if (resource == NULL)
goto no_resource; goto error_resource;
client = pw_resource_get_client(resource); client = pw_resource_get_client(resource);
dsp = pw_audio_dsp_new(pw_module_get_core(d->module), dsp = pw_audio_dsp_new(pw_module_get_core(d->module),
properties, properties,
sizeof(struct node_data)); sizeof(struct node_data));
properties = NULL;
if (dsp == NULL) { if (dsp == NULL) {
if (errno == ENOMEM) if (errno == ENOMEM)
goto no_mem; goto error_no_mem;
else else
goto usage; goto error_usage;
} }
nd = pw_audio_dsp_get_user_data(dsp); nd = pw_audio_dsp_get_user_data(dsp);
@ -129,38 +129,39 @@ static void *create_object(void *_data,
res = pw_global_bind(pw_node_get_global(dsp), client, res = pw_global_bind(pw_node_get_global(dsp), client,
PW_PERM_RWX, PW_VERSION_NODE_PROXY, new_id); PW_PERM_RWX, PW_VERSION_NODE_PROXY, new_id);
if (res < 0) if (res < 0)
goto no_bind; goto error_bind;
if ((bound_resource = pw_client_find_resource(client, new_id)) == NULL) if ((bound_resource = pw_client_find_resource(client, new_id)) == NULL)
goto no_bind; goto error_bind;
pw_resource_add_listener(bound_resource, &nd->resource_listener, &resource_events, nd); pw_resource_add_listener(bound_resource, &nd->resource_listener, &resource_events, nd);
pw_node_set_active(dsp, true); pw_node_set_active(dsp, true);
if (properties)
pw_properties_free(properties);
return dsp; return dsp;
no_resource: error_resource:
res = -EINVAL;
pw_log_error("audio-dsp needs a resource"); pw_log_error("audio-dsp needs a resource");
pw_resource_error(resource, -EINVAL, "no resource"); pw_resource_error(resource, res, "no resource");
goto done; goto error_cleanup;
usage: error_no_mem:
res = -errno;
pw_log_error("can't create node: %m");
pw_resource_error(resource, res, "no memory");
goto error_cleanup;
error_usage:
res = -EINVAL;
pw_log_error("usage: "AUDIO_DSP_USAGE); pw_log_error("usage: "AUDIO_DSP_USAGE);
pw_resource_error(resource, -EINVAL, "usage: "AUDIO_DSP_USAGE); pw_resource_error(resource, res, "usage: "AUDIO_DSP_USAGE);
goto done; goto error_cleanup;
no_mem: error_bind:
pw_log_error("can't create node");
pw_resource_error(resource, -ENOMEM, "no memory");
goto done;
no_bind:
pw_resource_error(resource, res, "can't bind dsp node"); pw_resource_error(resource, res, "can't bind dsp node");
goto done; goto error_cleanup;
done: error_cleanup:
if (properties) if (properties)
pw_properties_free(properties); pw_properties_free(properties);
errno = -res;
return NULL; return NULL;
} }
@ -179,9 +180,6 @@ static void module_destroy(void *data)
spa_list_for_each_safe(nd, t, &d->node_list, link) spa_list_for_each_safe(nd, t, &d->node_list, link)
pw_node_destroy(nd->dsp); pw_node_destroy(nd->dsp);
if (d->properties)
pw_properties_free(d->properties);
pw_factory_destroy(d->this); pw_factory_destroy(d->this);
} }
@ -210,7 +208,6 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
data = pw_factory_get_user_data(factory); data = pw_factory_get_user_data(factory);
data->this = factory; data->this = factory;
data->module = module; data->module = module;
data->properties = properties;
spa_list_init(&data->node_list); spa_list_init(&data->node_list);
pw_log_debug("module %p: new", module); pw_log_debug("module %p: new", module);

View file

@ -257,37 +257,34 @@ static const struct pw_node_events node_events = {
}; };
struct pw_node *pw_audio_dsp_new(struct pw_core *core, struct pw_node *pw_audio_dsp_new(struct pw_core *core,
const struct pw_properties *props, struct pw_properties *props,
size_t user_data_size) size_t user_data_size)
{ {
struct pw_node *node; struct pw_node *node;
struct node *n; struct node *n;
const char *api, *alias, *str, *factory; const char *api, *alias, *str, *factory;
char node_name[128]; char node_name[128];
struct pw_properties *pr;
enum pw_direction direction; enum pw_direction direction;
uint32_t max_buffer_size; uint32_t max_buffer_size;
int i; int i, res = -ENOENT;
pr = pw_properties_copy(props); if ((str = pw_properties_get(props, "audio-dsp.direction")) == NULL) {
if ((str = pw_properties_get(pr, "audio-dsp.direction")) == NULL) {
pw_log_error("missing audio-dsp.direction property"); pw_log_error("missing audio-dsp.direction property");
goto error; goto error;
} }
direction = pw_properties_parse_int(str); direction = pw_properties_parse_int(str);
if ((str = pw_properties_get(pr, "audio-dsp.maxbuffer")) == NULL) { if ((str = pw_properties_get(props, "audio-dsp.maxbuffer")) == NULL) {
pw_log_error("missing audio-dsp.maxbuffer property"); pw_log_error("missing audio-dsp.maxbuffer property");
goto error; goto error;
} }
max_buffer_size = pw_properties_parse_int(str); max_buffer_size = pw_properties_parse_int(str);
if ((api = pw_properties_get(pr, PW_KEY_DEVICE_API)) == NULL) { if ((api = pw_properties_get(props, PW_KEY_DEVICE_API)) == NULL) {
pw_log_error("missing "PW_KEY_DEVICE_API" property"); pw_log_error("missing "PW_KEY_DEVICE_API" property");
goto error; goto error;
} }
if ((alias = pw_properties_get(pr, "audio-dsp.name")) == NULL) { if ((alias = pw_properties_get(props, "audio-dsp.name")) == NULL) {
pw_log_error("missing audio-dsp.name property"); pw_log_error("missing audio-dsp.name property");
goto error; goto error;
} }
@ -298,34 +295,36 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
node_name[i] = '_'; node_name[i] = '_';
} }
pw_properties_set(pr, pw_properties_set(props,
PW_KEY_MEDIA_CLASS, PW_KEY_MEDIA_CLASS,
direction == PW_DIRECTION_OUTPUT ? direction == PW_DIRECTION_OUTPUT ?
"Audio/DSP/Playback" : "Audio/DSP/Playback" :
"Audio/DSP/Capture"); "Audio/DSP/Capture");
pw_properties_set(pr, PW_KEY_NODE_DRIVER, NULL); pw_properties_set(props, PW_KEY_NODE_DRIVER, NULL);
if ((str = pw_properties_get(pr, PW_KEY_NODE_ID)) != NULL) if ((str = pw_properties_get(props, PW_KEY_NODE_ID)) != NULL)
pw_properties_set(pr, PW_KEY_NODE_SESSION, str); pw_properties_set(props, PW_KEY_NODE_SESSION, str);
if (direction == PW_DIRECTION_OUTPUT) { if (direction == PW_DIRECTION_OUTPUT) {
pw_properties_set(pr, "merger.monitor", "1"); pw_properties_set(props, "merger.monitor", "1");
factory = "merge"; factory = "merge";
} else { } else {
factory = "split"; factory = "split";
} }
pw_properties_set(pr, "factory.mode", factory); pw_properties_set(props, "factory.mode", factory);
factory = "audioconvert"; factory = "audioconvert";
pw_properties_set(pr, SPA_KEY_LIBRARY_NAME, "audioconvert/libspa-audioconvert"); pw_properties_set(props, SPA_KEY_LIBRARY_NAME, "audioconvert/libspa-audioconvert");
node = pw_spa_node_load(core, NULL, NULL, node = pw_spa_node_load(core, NULL, NULL,
factory, factory,
node_name, node_name,
PW_SPA_NODE_FLAG_ACTIVATE | PW_SPA_NODE_FLAG_NO_REGISTER, PW_SPA_NODE_FLAG_ACTIVATE | PW_SPA_NODE_FLAG_NO_REGISTER,
pr, sizeof(struct node) + user_data_size); pw_properties_copy(props),
sizeof(struct node) + user_data_size);
if (node == NULL) { if (node == NULL) {
pw_log_error("can't load spa node"); res = -errno;
pw_log_error("can't load spa node: %m");
goto error; goto error;
} }
@ -333,7 +332,7 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
n->core = core; n->core = core;
n->node = node; n->node = node;
n->direction = direction; n->direction = direction;
n->props = pw_properties_copy(pr); n->props = props;
spa_list_init(&n->ports); spa_list_init(&n->ports);
n->max_buffer_size = max_buffer_size; n->max_buffer_size = max_buffer_size;
@ -345,8 +344,10 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
return node; return node;
error: error:
pw_properties_free(pr); if (props)
pw_properties_free(props);
errno = -res;
return NULL; return NULL;
} }

View file

@ -40,7 +40,7 @@ extern "C" {
struct pw_node * struct pw_node *
pw_audio_dsp_new(struct pw_core *core, pw_audio_dsp_new(struct pw_core *core,
const struct pw_properties *properties, struct pw_properties *properties,
size_t user_data_size); size_t user_data_size);
void *pw_audio_dsp_get_user_data(struct pw_node *node); void *pw_audio_dsp_get_user_data(struct pw_node *node);

View file

@ -346,7 +346,7 @@ impl_node_port_enum_params(void *object, int seq,
result.id = id; result.id = id;
result.next = start; result.next = start;
next: next:
result.index = result.next++; result.index = result.next++;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));

View file

@ -99,6 +99,7 @@ error_node:
pw_log_error("can't create node: %s", spa_strerror(res)); pw_log_error("can't create node: %s", spa_strerror(res));
pw_resource_error(resource, res, "can't create node: %s", spa_strerror(res)); pw_resource_error(resource, res, "can't create node: %s", spa_strerror(res));
goto error_exit_free; goto error_exit_free;
error_exit_free: error_exit_free:
pw_resource_destroy(node_resource); pw_resource_destroy(node_resource);
error_exit: error_exit:

View file

@ -244,7 +244,7 @@ static struct mem *ensure_mem(struct impl *impl, int fd, uint32_t type, uint32_t
type, type,
m->fd, m->fd,
m->flags); m->flags);
found: found:
m->ref++; m->ref++;
pw_log_debug("client-node %p: mem %d, ref %d", impl, m->id, m->ref); pw_log_debug("client-node %p: mem %d, ref %d", impl, m->id, m->ref);
return m; return m;
@ -328,7 +328,7 @@ static struct io *update_io(struct node *this,
spa_log_debug(this->log, "node %p: add io %p %s %d", this, io, spa_log_debug(this->log, "node %p: add io %p %s %d", this, io,
spa_debug_type_find_name(spa_type_io, id), memid); spa_debug_type_find_name(spa_type_io, id), memid);
found: found:
return io; return io;
} }
@ -1680,10 +1680,13 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
const struct spa_support *support; const struct spa_support *support;
uint32_t n_support; uint32_t n_support;
const char *name; const char *name;
int res;
impl = calloc(1, sizeof(struct impl)); impl = calloc(1, sizeof(struct impl));
if (impl == NULL) if (impl == NULL) {
return NULL; res = -errno;
goto error_exit_cleanup;
}
this = &impl->this; this = &impl->this;
@ -1714,6 +1717,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
(struct spa_node *)&impl->node.node, (struct spa_node *)&impl->node.node,
NULL, NULL,
properties, 0); properties, 0);
if (this->node == NULL) if (this->node == NULL)
goto error_no_node; goto error_no_node;
@ -1738,10 +1742,20 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
return this; return this;
error_no_node: error_no_node:
pw_resource_destroy(this->resource); res = -errno;
node_clear(&impl->node); node_clear(&impl->node);
properties = NULL;
goto error_exit_free;
error_exit_free:
free(impl); free(impl);
error_exit_cleanup:
if (resource)
pw_resource_destroy(resource);
if (properties)
pw_properties_free(properties);
errno = -res;
return NULL; return NULL;
} }

View file

@ -136,7 +136,7 @@ static int impl_node_enum_params(void *object, int seq,
result.id = id; result.id = id;
result.next = start; result.next = start;
next: next:
result.index = result.next++; result.index = result.next++;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -1252,10 +1252,13 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
struct pw_properties *props; struct pw_properties *props;
uint32_t n_support; uint32_t n_support;
const char *name; const char *name;
int res;
impl = calloc(1, sizeof(struct impl)); impl = calloc(1, sizeof(struct impl));
if (impl == NULL) if (impl == NULL) {
return NULL; res = -errno;
goto error_exit_cleanup;
}
this = &impl->this; this = &impl->this;
@ -1271,8 +1274,11 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
parent, parent,
props, props,
false); false);
if (impl->client_node == NULL) resource = NULL;
goto error_no_node; if (impl->client_node == NULL) {
res = -errno;
goto error_exit_free;
}
impl->cnode = pw_node_get_implementation(impl->client_node->node); impl->cnode = pw_node_get_implementation(impl->client_node->node);
spa_node_set_callbacks(impl->cnode, &node_callbacks, impl); spa_node_set_callbacks(impl->cnode, &node_callbacks, impl);
@ -1293,8 +1299,11 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
(struct spa_node *)&impl->node.node, (struct spa_node *)&impl->node.node,
NULL, NULL,
properties, 0); properties, 0);
if (this->node == NULL) properties = NULL;
goto error_no_node; if (this->node == NULL) {
res = -errno;
goto error_exit_free_client_node;
}
this->node->remote = true; this->node->remote = true;
@ -1305,9 +1314,16 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
return this; return this;
error_no_node: error_exit_free_client_node:
pw_resource_destroy(resource); pw_client_node_destroy(impl->client_node);
error_exit_free:
free(impl); free(impl);
error_exit_cleanup:
if (resource)
pw_resource_destroy(resource);
if (properties)
pw_properties_free(properties);
errno = -res;
return NULL; return NULL;
} }

View file

@ -656,9 +656,7 @@ client_node_port_set_param(void *object,
port = pw_node_find_port(data->node, direction, port_id); port = pw_node_find_port(data->node, direction, port_id);
if (port == NULL) { if (port == NULL) {
res = -EINVAL; res = -EINVAL;
pw_proxy_error(proxy, res, "unknown %s port %d", goto error_exit;
direction == SPA_DIRECTION_INPUT ? "input" : "output", port_id);
goto done;
} }
pw_log_debug("port %p: set param %d %p", port, id, param); pw_log_debug("port %p: set param %d %p", port, id, param);
@ -672,12 +670,14 @@ client_node_port_set_param(void *object,
} }
res = pw_port_set_param(port, id, flags, param); res = pw_port_set_param(port, id, flags, param);
if (res < 0) { if (res < 0)
pw_proxy_error(proxy, res, "can't set port param: %s", spa_strerror(res)); goto error_exit;
goto done;
}
done: return res;
error_exit:
pw_log_error("port %p: set_param %d %p: %s", port, id, param, spa_strerror(res));
pw_proxy_error(proxy, res, "port_set_param: %s", spa_strerror(res));
return res; return res;
} }
@ -696,9 +696,8 @@ client_node_port_use_buffers(void *object,
mix = ensure_mix(data, direction, port_id, mix_id); mix = ensure_mix(data, direction, port_id, mix_id);
if (mix == NULL) { if (mix == NULL) {
res = -EINVAL; res = -ENOENT;
pw_proxy_error(proxy, res, "can add mix"); goto error_exit;
goto done;
} }
prot = PROT_READ | (direction == SPA_DIRECTION_OUTPUT ? PROT_WRITE : 0); prot = PROT_READ | (direction == SPA_DIRECTION_OUTPUT ? PROT_WRITE : 0);
@ -716,17 +715,14 @@ client_node_port_use_buffers(void *object,
m = find_mem(data, buffers[i].mem_id); m = find_mem(data, buffers[i].mem_id);
if (m == NULL) { if (m == NULL) {
pw_log_error("unknown memory id %u", buffers[i].mem_id); res = -ENODEV;
res = -EINVAL; goto error_exit_cleanup;
pw_proxy_error(proxy, res, "unknown memory %u", buffers[i].mem_id);
goto cleanup;
} }
bid = pw_array_add(&mix->buffers, sizeof(struct buffer)); bid = pw_array_add(&mix->buffers, sizeof(struct buffer));
if (bid == NULL) { if (bid == NULL) {
res = -errno; res = -errno;
pw_proxy_error(proxy, res, "error allocating buffers : %m"); goto error_exit_cleanup;
goto cleanup;
} }
bid->id = i; bid->id = i;
@ -735,8 +731,7 @@ client_node_port_use_buffers(void *object,
buffers[i].offset, buffers[i].size); buffers[i].offset, buffers[i].size);
if (bmem.map.ptr == NULL) { if (bmem.map.ptr == NULL) {
res = -errno; res = -errno;
pw_proxy_error(proxy, res, "use_buffers: can't mmap memory: %m"); goto error_exit_cleanup;
goto cleanup;
} }
if (mlock(bmem.map.ptr, bmem.map.map.size) < 0) if (mlock(bmem.map.ptr, bmem.map.map.size) < 0)
pw_log_warn("Failed to mlock memory %u %u: %m", pw_log_warn("Failed to mlock memory %u %u: %m",
@ -754,8 +749,7 @@ client_node_port_use_buffers(void *object,
b = bid->buf = malloc(size); b = bid->buf = malloc(size);
if (b == NULL) { if (b == NULL) {
res = -errno; res = -errno;
pw_proxy_error(proxy, res, "can't alloc memory: %s", spa_strerror(res)); goto error_exit_cleanup;
goto cleanup;
} }
memcpy(b, buffers[i].buffer, sizeof(struct spa_buffer)); memcpy(b, buffers[i].buffer, sizeof(struct spa_buffer));
@ -795,9 +789,8 @@ client_node_port_use_buffers(void *object,
if (bm == NULL) { if (bm == NULL) {
pw_log_error("unknown buffer mem %u", mem_id); pw_log_error("unknown buffer mem %u", mem_id);
res = -EINVAL; res = -ENODEV;
pw_proxy_error(proxy, res, "unknown buffer mem %u", mem_id); goto error_exit_cleanup;
goto cleanup;
} }
d->fd = bm->fd; d->fd = bm->fd;
@ -824,15 +817,16 @@ client_node_port_use_buffers(void *object,
} }
if ((res = pw_port_use_buffers(mix->port, mix->mix_id, bufs, n_buffers)) < 0) if ((res = pw_port_use_buffers(mix->port, mix->mix_id, bufs, n_buffers)) < 0)
pw_proxy_error(proxy, res, "can't use buffers: %s", spa_strerror(res)); goto error_exit_cleanup;
done:
return res; return res;
cleanup: error_exit_cleanup:
clear_buffers(data, mix); clear_buffers(data, mix);
goto done; error_exit:
pw_log_error("port %p: use_buffers: %s", mix, spa_strerror(res));
pw_proxy_error(proxy, res, "port_use_buffers error: %s", spa_strerror(res));
return res;
} }
static int static int
@ -854,9 +848,8 @@ client_node_port_set_io(void *object,
mix = ensure_mix(data, direction, port_id, mix_id); mix = ensure_mix(data, direction, port_id, mix_id);
if (mix == NULL) { if (mix == NULL) {
res = -EINVAL; res = -ENOENT;
pw_proxy_error(proxy, res, "can't get mixer: %s", spa_strerror(res)); goto error_exit;
return res;
} }
if (memid == SPA_ID_INVALID) { if (memid == SPA_ID_INVALID) {
@ -866,17 +859,14 @@ client_node_port_set_io(void *object,
else { else {
m = find_mem(data, memid); m = find_mem(data, memid);
if (m == NULL) { if (m == NULL) {
pw_log_warn("unknown memory id %u", memid); res = -ENODEV;
res = -EINVAL; goto error_exit;
pw_proxy_error(proxy, res, "unknown memory id %u", memid);
return res;
} }
ptr = mem_map(data, &m->map, m->fd, ptr = mem_map(data, &m->map, m->fd,
PROT_READ|PROT_WRITE, offset, size); PROT_READ|PROT_WRITE, offset, size);
if (ptr == NULL) { if (ptr == NULL) {
res = -errno; res = -errno;
pw_proxy_error(proxy, res, "port_set_io: mmap failed: %m"); goto error_exit;
return res;
} }
m->ref++; m->ref++;
@ -901,9 +891,14 @@ client_node_port_set_io(void *object,
id, id,
ptr, ptr,
size)) < 0) size)) < 0)
pw_proxy_error(proxy, res, "set_io failed: %s", spa_strerror(res)); goto error_exit;
} }
return res; return res;
error_exit:
pw_log_error("port %p: set_io: %s", mix, spa_strerror(res));
pw_proxy_error(proxy, res, "port_set_io failed: %s", spa_strerror(res));
return res;
} }
static int link_signal_func(void *user_data) static int link_signal_func(void *user_data)
@ -946,16 +941,14 @@ client_node_set_activation(void *object,
else { else {
m = find_mem(data, memid); m = find_mem(data, memid);
if (m == NULL) { if (m == NULL) {
pw_log_warn("unknown memory id %u", memid); res = -ENODEV;
res = -EINVAL; goto error_exit;
pw_proxy_error(proxy, res, "unknown memory id %u", memid);
return res;
} }
ptr = mem_map(data, &m->map, m->fd, ptr = mem_map(data, &m->map, m->fd,
PROT_READ|PROT_WRITE, offset, size); PROT_READ|PROT_WRITE, offset, size);
if (ptr == NULL) { if (ptr == NULL) {
pw_proxy_error(proxy, -errno, "set_activation: mmap failed: %m"); res = -errno;
return -errno; goto error_exit;
} }
m->ref++; m->ref++;
} }
@ -970,8 +963,10 @@ client_node_set_activation(void *object,
if (ptr) { if (ptr) {
link = pw_array_add(&data->links, sizeof(struct link)); link = pw_array_add(&data->links, sizeof(struct link));
if (link == NULL) if (link == NULL) {
return -errno; res = -errno;
goto error_exit;
}
link->node_id = node_id; link->node_id = node_id;
link->mem_id = memid; link->mem_id = memid;
link->target.activation = ptr; link->target.activation = ptr;
@ -988,13 +983,16 @@ client_node_set_activation(void *object,
} else { } else {
link = find_activation(&data->links, node_id); link = find_activation(&data->links, node_id);
if (link == NULL) { if (link == NULL) {
res = -EINVAL; res = -ENOENT;
goto exit; goto error_exit;
} }
clear_link(data, link); clear_link(data, link);
} }
return res;
exit: error_exit:
pw_log_error("node %p: set activation %d: %s", node, node_id, spa_strerror(res));
pw_proxy_error(proxy, res, "set_activation: %s", spa_strerror(res));
return res; return res;
} }

View file

@ -170,17 +170,17 @@ process_messages(struct client_data *data)
if (demarshal[msg->opcode].func(resource, msg) < 0) if (demarshal[msg->opcode].func(resource, msg) < 0)
goto invalid_message; goto invalid_message;
} }
done: done:
core->current_client = NULL; core->current_client = NULL;
return; return;
invalid_method: invalid_method:
pw_log_error("protocol-native %p: invalid method %u on resource %u", pw_log_error("protocol-native %p: invalid method %u on resource %u",
client->protocol, msg->opcode, msg->id); client->protocol, msg->opcode, msg->id);
pw_resource_error(resource, -EINVAL, "invalid method %u", msg->opcode); pw_resource_error(resource, -EINVAL, "invalid method %u", msg->opcode);
pw_client_destroy(client); pw_client_destroy(client);
goto done; goto done;
invalid_message: invalid_message:
pw_log_error("protocol-native %p: invalid message received %u %u", pw_log_error("protocol-native %p: invalid message received %u %u",
client->protocol, msg->id, msg->opcode); client->protocol, msg->id, msg->opcode);
pw_resource_error(resource, -EINVAL, "invalid message %u", msg->opcode); pw_resource_error(resource, -EINVAL, "invalid message %u", msg->opcode);
@ -312,9 +312,9 @@ static struct pw_client *client_new(struct server *s, int fd)
return client; return client;
cleanup_client: cleanup_client:
pw_client_destroy(client); pw_client_destroy(client);
exit: exit:
return NULL; return NULL;
} }
@ -364,10 +364,10 @@ static int lock_socket(struct server *s)
} }
return 0; return 0;
err_fd: err_fd:
close(s->fd_lock); close(s->fd_lock);
s->fd_lock = -1; s->fd_lock = -1;
err: err:
*s->lock_addr = 0; *s->lock_addr = 0;
*s->addr.sun_path = 0; *s->addr.sun_path = 0;
return res; return res;
@ -457,9 +457,9 @@ static int add_socket(struct pw_protocol *protocol, struct server *s)
} }
return 0; return 0;
error_close: error_close:
close(fd); close(fd);
error: error:
return res; return res;
} }

View file

@ -195,7 +195,7 @@ static int refill_buffer(struct pw_protocol_native_connection *conn, struct buff
return 0; return 0;
/* ERRORS */ /* ERRORS */
recv_error: recv_error:
pw_log_error("could not recvmsg on fd %d: %s", conn->fd, strerror(errno)); pw_log_error("could not recvmsg on fd %d: %s", conn->fd, strerror(errno));
return -errno; return -errno;
} }
@ -245,7 +245,7 @@ struct pw_protocol_native_connection *pw_protocol_native_connection_new(struct p
return this; return this;
no_mem: no_mem:
free(impl->out.buffer_data); free(impl->out.buffer_data);
free(impl->in.buffer_data); free(impl->in.buffer_data);
free(impl); free(impl);
@ -514,7 +514,7 @@ int pw_protocol_native_connection_flush(struct pw_protocol_native_connection *co
return 0; return 0;
/* ERRORS */ /* ERRORS */
send_error: send_error:
res = -errno; res = -errno;
pw_log_error("could not sendmsg: %s", strerror(errno)); pw_log_error("could not sendmsg: %s", strerror(errno));
return res; return res;

View file

@ -128,7 +128,7 @@ struct pw_rtkit_bus *pw_rtkit_bus_get_system(void)
return bus; return bus;
error: error:
free(bus); free(bus);
pw_log_error("Failed to connect to system bus: %s", error.message); pw_log_error("Failed to connect to system bus: %s", error.message);
dbus_error_free(&error); dbus_error_free(&error);
@ -227,7 +227,7 @@ static long long rtkit_get_int_property(struct pw_rtkit_bus *connection, const c
dbus_message_iter_next(&iter); dbus_message_iter_next(&iter);
} }
finish: finish:
if (m) if (m)
dbus_message_unref(m); dbus_message_unref(m);
@ -313,7 +313,7 @@ int pw_rtkit_make_realtime(struct pw_rtkit_bus *connection, pid_t thread, int pr
ret = 0; ret = 0;
finish: finish:
if (m) if (m)
dbus_message_unref(m); dbus_message_unref(m);
@ -372,7 +372,7 @@ int pw_rtkit_make_high_priority(struct pw_rtkit_bus *connection, pid_t thread, i
ret = 0; ret = 0;
finish: finish:
if (m) if (m)
dbus_message_unref(m); dbus_message_unref(m);
@ -519,7 +519,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
return 0; return 0;
error: error:
free(impl); free(impl);
return res; return res;
} }

View file

@ -57,6 +57,9 @@ struct device_data {
static void module_destroy(void *_data) static void module_destroy(void *_data)
{ {
struct device_data *data = _data; struct device_data *data = _data;
spa_hook_remove(&data->module_listener);
pw_device_destroy(data->this); pw_device_destroy(data->this);
} }
@ -69,23 +72,26 @@ SPA_EXPORT
int pipewire__module_init(struct pw_module *module, const char *args) int pipewire__module_init(struct pw_module *module, const char *args)
{ {
struct pw_properties *props = NULL; struct pw_properties *props = NULL;
char **argv; char **argv = NULL;
int n_tokens; int n_tokens;
struct pw_core *core = pw_module_get_core(module); struct pw_core *core = pw_module_get_core(module);
struct pw_device *device; struct pw_device *device;
struct device_data *data; struct device_data *data;
int res;
if (args == NULL) if (args == NULL)
goto wrong_arguments; goto error_arguments;
argv = pw_split_strv(args, " \t", 3, &n_tokens); argv = pw_split_strv(args, " \t", 3, &n_tokens);
if (n_tokens < 2) if (n_tokens < 2)
goto not_enough_arguments; goto error_arguments;
if (n_tokens == 3) { if (n_tokens == 3) {
props = pw_properties_new_string(argv[2]); props = pw_properties_new_string(argv[2]);
if (props == NULL) if (props == NULL) {
return -ENOMEM; res = -errno;
goto error_exit_cleanup;
}
} }
device = pw_spa_device_load(core, device = pw_spa_device_load(core,
@ -95,12 +101,13 @@ int pipewire__module_init(struct pw_module *module, const char *args)
0, 0,
props, props,
sizeof(struct device_data)); sizeof(struct device_data));
if (device == NULL) {
res = -errno;
goto error_exit_cleanup;
}
pw_free_strv(argv); pw_free_strv(argv);
if (device == NULL)
return -ENOMEM;
data = pw_spa_device_get_user_data(device); data = pw_spa_device_get_user_data(device);
data->this = device; data->this = device;
data->core = core; data->core = core;
@ -112,9 +119,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
return 0; return 0;
not_enough_arguments: error_arguments:
pw_free_strv(argv); res = -EINVAL;
wrong_arguments:
pw_log_error("usage: module-spa-device " MODULE_USAGE); pw_log_error("usage: module-spa-device " MODULE_USAGE);
return -EINVAL; goto error_exit_cleanup;
error_exit_cleanup:
if (argv)
pw_free_strv(argv);
return res;
} }

View file

@ -72,22 +72,24 @@ int pipewire__module_init(struct pw_module *module, const char *args)
{ {
struct pw_core *core = pw_module_get_core(module); struct pw_core *core = pw_module_get_core(module);
struct pw_properties *props = NULL; struct pw_properties *props = NULL;
char **argv; char **argv = NULL;
int n_tokens; int n_tokens, res;
struct pw_spa_monitor *monitor; struct pw_spa_monitor *monitor;
struct data *data; struct data *data;
if (args == NULL) if (args == NULL)
goto wrong_arguments; goto error_arguments;
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens); argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
if (n_tokens < 2) if (n_tokens < 2)
goto not_enough_arguments; goto error_arguments;
if (n_tokens == 3) { if (n_tokens == 3) {
props = pw_properties_new_string(argv[2]); props = pw_properties_new_string(argv[2]);
if (props == NULL) if (props == NULL) {
return -ENOMEM; res = -errno;
goto error_exit_cleanup;
}
} }
monitor = pw_spa_monitor_load(core, monitor = pw_spa_monitor_load(core,
@ -95,23 +97,28 @@ int pipewire__module_init(struct pw_module *module, const char *args)
argv[0], argv[1], argv[0], argv[1],
props, props,
sizeof(struct data)); sizeof(struct data));
if (monitor == NULL) if (monitor == NULL) {
return -ENOMEM; res = -errno;
goto error_exit_cleanup;
}
pw_free_strv(argv);
data = monitor->user_data; data = monitor->user_data;
data->monitor = monitor; data->monitor = monitor;
pw_free_strv(argv);
pw_module_add_listener(module, &data->module_listener, &module_events, data); pw_module_add_listener(module, &data->module_listener, &module_events, data);
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props)); pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
return 0; return 0;
not_enough_arguments: error_arguments:
pw_free_strv(argv); res = -EINVAL;
wrong_arguments:
pw_log_error("usage: module-spa-monitor " MODULE_USAGE); pw_log_error("usage: module-spa-monitor " MODULE_USAGE);
return -EINVAL; goto error_exit_cleanup;
error_exit_cleanup:
if (argv)
pw_free_strv(argv);
return res;
} }

View file

@ -83,13 +83,14 @@ static void *create_object(void *_data,
struct pw_node *node; struct pw_node *node;
const char *factory_name, *name; const char *factory_name, *name;
struct node_data *nd; struct node_data *nd;
int res;
if (properties == NULL) if (properties == NULL)
goto no_properties; goto error_properties;
factory_name = pw_properties_get(properties, SPA_KEY_FACTORY_NAME); factory_name = pw_properties_get(properties, SPA_KEY_FACTORY_NAME);
if (factory_name == NULL) if (factory_name == NULL)
goto no_properties; goto error_properties;
name = pw_properties_get(properties, PW_KEY_NODE_NAME); name = pw_properties_get(properties, PW_KEY_NODE_NAME);
if (name == NULL) if (name == NULL)
@ -104,7 +105,7 @@ static void *create_object(void *_data,
properties, properties,
sizeof(struct node_data)); sizeof(struct node_data));
if (node == NULL) if (node == NULL)
goto no_mem; goto error_create_node;
nd = pw_spa_node_get_user_data(node); nd = pw_spa_node_get_user_data(node);
nd->node = node; nd->node = node;
@ -120,17 +121,24 @@ static void *create_object(void *_data,
return node; return node;
no_properties: error_properties:
res = -EINVAL;
pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this); pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
if (resource) { if (resource)
pw_resource_error(resource, -EINVAL, "usage: " FACTORY_USAGE); pw_resource_error(resource, res, "usage: " FACTORY_USAGE);
} goto error_exit_cleanup;
return NULL; error_create_node:
no_mem: res = -errno;
pw_log_error("can't create node: no memory"); pw_log_error("can't create node: %m");
if (resource) { if (resource)
pw_resource_error(resource, -ENOMEM, "no memory"); pw_resource_error(resource, res, "can't create node: %s", spa_strerror(res));
} goto error_exit;
error_exit_cleanup:
if (properties)
pw_properties_free(properties);
error_exit:
errno = -res;
return NULL; return NULL;
} }

View file

@ -60,6 +60,7 @@ struct node_data {
static void module_destroy(void *_data) static void module_destroy(void *_data)
{ {
struct node_data *data = _data; struct node_data *data = _data;
spa_hook_remove(&data->module_listener);
pw_node_destroy(data->this); pw_node_destroy(data->this);
} }
@ -72,23 +73,25 @@ SPA_EXPORT
int pipewire__module_init(struct pw_module *module, const char *args) int pipewire__module_init(struct pw_module *module, const char *args)
{ {
struct pw_properties *props = NULL; struct pw_properties *props = NULL;
char **argv; char **argv = NULL;
int n_tokens; int n_tokens, res;
struct pw_core *core = pw_module_get_core(module); struct pw_core *core = pw_module_get_core(module);
struct pw_node *node; struct pw_node *node;
struct node_data *data; struct node_data *data;
if (args == NULL) if (args == NULL)
goto wrong_arguments; goto error_arguments;
argv = pw_split_strv(args, " \t", 3, &n_tokens); argv = pw_split_strv(args, " \t", 3, &n_tokens);
if (n_tokens < 2) if (n_tokens < 2)
goto not_enough_arguments; goto error_arguments;
if (n_tokens == 3) { if (n_tokens == 3) {
props = pw_properties_new_string(argv[2]); props = pw_properties_new_string(argv[2]);
if (props == NULL) if (props == NULL) {
return -ENOMEM; res = -errno;
goto error_exit_cleanup;
}
} }
node = pw_spa_node_load(core, node = pw_spa_node_load(core,
@ -99,10 +102,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
props, props,
sizeof(struct node_data)); sizeof(struct node_data));
pw_free_strv(argv); if (node == NULL) {
res = -errno;
goto error_exit_cleanup;
}
if (node == NULL) pw_free_strv(argv);
return -ENOMEM;
data = pw_spa_node_get_user_data(node); data = pw_spa_node_get_user_data(node);
data->this = node; data->this = node;
@ -116,9 +121,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
return 0; return 0;
not_enough_arguments: error_arguments:
pw_free_strv(argv); res = -EINVAL;
wrong_arguments:
pw_log_error("usage: module-spa-node " MODULE_USAGE); pw_log_error("usage: module-spa-node " MODULE_USAGE);
return -EINVAL; goto error_exit_cleanup;
error_exit_cleanup:
if (argv)
pw_free_strv(argv);
return res;
} }

View file

@ -142,30 +142,34 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
handle = pw_core_load_spa_handle(core, factory_name, handle = pw_core_load_spa_handle(core, factory_name,
properties ? &properties->dict : NULL); properties ? &properties->dict : NULL);
if (handle == NULL) { if (handle == NULL)
res = -errno; goto error_load;
pw_log_error("can't load device handle: %m");
goto exit;
}
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0)
pw_log_error("can't get device interface %d", res); goto error_interface;
goto exit_unload;
}
this = pw_spa_device_new(core, owner, parent, name, flags, this = pw_spa_device_new(core, owner, parent, name, flags,
iface, handle, properties, user_data_size); iface, handle, properties, user_data_size);
if (this == NULL) { if (this == NULL)
res = -errno; goto error_device;
pw_log_error("can't create device: %m");
goto exit_unload;
}
return this; return this;
exit_unload: error_load:
res = -errno;
pw_log_error("can't load device handle: %m");
goto error_exit;
error_interface:
pw_log_error("can't get device interface %d", res);
goto error_exit_unload;
error_device:
res = -errno;
pw_log_error("can't create device: %m");
goto error_exit_unload;
error_exit_unload:
pw_unload_spa_handle(handle); pw_unload_spa_handle(handle);
exit: error_exit:
errno = -res; errno = -res;
return NULL; return NULL;
} }

View file

@ -117,18 +117,18 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
if (handle == NULL) { if (handle == NULL) {
res = -errno; res = -errno;
pw_log_error("can't make factory instance: %m"); pw_log_error("can't make factory instance: %m");
goto error_free_props; goto error_exit_free_props;
} }
if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
pw_log_error("can't get %d interface: %s", info->type, spa_strerror(res)); pw_log_error("can't get %d interface: %s", info->type, spa_strerror(res));
goto error_free_handle; goto error_exit_free_handle;
} }
obj = calloc(1, sizeof(struct monitor_object)); obj = calloc(1, sizeof(struct monitor_object));
if (obj == NULL) { if (obj == NULL) {
res = -errno; res = -errno;
goto error_free_handle; goto error_exit_free_handle;
} }
obj->id = id; obj->id = id;
obj->name = strdup(name); obj->name = strdup(name);
@ -149,19 +149,19 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
default: default:
res = -ENOTSUP; res = -ENOTSUP;
pw_log_error("interface %d not implemented", obj->type); pw_log_error("interface %d not implemented", obj->type);
goto error_free_object; goto error_exit_free_object;
} }
spa_list_append(&impl->item_list, &obj->link); spa_list_append(&impl->item_list, &obj->link);
return obj; return obj;
error_free_object: error_exit_free_object:
free(obj->name); free(obj->name);
free(obj); free(obj);
error_free_handle: error_exit_free_handle:
pw_unload_spa_handle(handle); pw_unload_spa_handle(handle);
error_free_props: error_exit_free_props:
pw_properties_free(props); pw_properties_free(props);
errno = -res; errno = -res;
return NULL; return NULL;
@ -279,18 +279,18 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
properties ? &properties->dict : NULL); properties ? &properties->dict : NULL);
if (handle == NULL) { if (handle == NULL) {
res = -errno; res = -errno;
goto exit; goto error_exit;
} }
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %s", spa_strerror(res)); pw_log_error("can't get MONITOR interface: %s", spa_strerror(res));
goto exit_unload; goto error_exit_unload;
} }
impl = calloc(1, sizeof(struct impl) + user_data_size); impl = calloc(1, sizeof(struct impl) + user_data_size);
if (impl == NULL) { if (impl == NULL) {
res = -errno; res = -errno;
goto exit_unload; goto error_exit_unload;
} }
impl->core = core; impl->core = core;
@ -313,12 +313,11 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
return this; return this;
exit_unload: error_exit_unload:
pw_unload_spa_handle(handle); pw_unload_spa_handle(handle);
exit: error_exit:
errno = -res; errno = -res;
return NULL; return NULL;
} }
void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor) void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)

View file

@ -125,14 +125,17 @@ pw_spa_node_new(struct pw_core *core,
int res; int res;
this = pw_node_new(core, name, properties, sizeof(struct impl) + user_data_size); this = pw_node_new(core, name, properties, sizeof(struct impl) + user_data_size);
if (this == NULL) if (this == NULL) {
return NULL; res = -errno;
goto error_exit;
}
impl = this->user_data; impl = this->user_data;
impl->this = this; impl->this = this;
impl->owner = owner; impl->owner = owner;
impl->parent = parent; impl->parent = parent;
impl->node = node; impl->node = node;
impl->handle = handle;
impl->flags = flags; impl->flags = flags;
if (user_data_size > 0) if (user_data_size > 0)
@ -140,7 +143,7 @@ pw_spa_node_new(struct pw_core *core,
pw_node_add_listener(this, &impl->node_listener, &node_events, impl); pw_node_add_listener(this, &impl->node_listener, &node_events, impl);
if ((res = pw_node_set_implementation(this, impl->node)) < 0) if ((res = pw_node_set_implementation(this, impl->node)) < 0)
goto clean_node; goto error_exit_clean_node;
if (flags & PW_SPA_NODE_FLAG_ASYNC) { if (flags & PW_SPA_NODE_FLAG_ASYNC) {
impl->init_pending = spa_node_sync(impl->node, res); impl->init_pending = spa_node_sync(impl->node, res);
@ -149,8 +152,12 @@ pw_spa_node_new(struct pw_core *core,
} }
return this; return this;
clean_node: error_exit_clean_node:
pw_node_destroy(this); pw_node_destroy(this);
handle = NULL;
error_exit:
if (handle)
pw_unload_spa_handle(handle);
errno = -res; errno = -res;
return NULL; return NULL;
@ -257,12 +264,12 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
properties ? &properties->dict : NULL); properties ? &properties->dict : NULL);
if (handle == NULL) { if (handle == NULL) {
res = -errno; res = -errno;
goto exit; goto error_exit_cleanup;
} }
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
pw_log_error("can't get node interface %d", res); pw_log_error("can't get node interface %d", res);
goto exit_unload; goto error_exit_unload;
} }
if (SPA_RESULT_IS_ASYNC(res)) if (SPA_RESULT_IS_ASYNC(res))
flags |= PW_SPA_NODE_FLAG_ASYNC; flags |= PW_SPA_NODE_FLAG_ASYNC;
@ -279,18 +286,20 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
spa_node, handle, properties, user_data_size); spa_node, handle, properties, user_data_size);
if (this == NULL) { if (this == NULL) {
res = -errno; res = -errno;
goto exit; goto error_exit;
} }
impl = this->user_data; impl = this->user_data;
impl->handle = handle;
impl->factory_name = strdup(factory_name); impl->factory_name = strdup(factory_name);
return this; return this;
exit_unload: error_exit_unload:
pw_unload_spa_handle(handle); pw_unload_spa_handle(handle);
exit: error_exit_cleanup:
if (properties)
pw_properties_free(properties);
error_exit:
errno = -res; errno = -res;
return NULL; return NULL;
} }

View file

@ -68,7 +68,7 @@ find_permission(struct pw_client *client, uint32_t id)
return p; return p;
do_default: do_default:
return pw_array_get_unchecked(&impl->permissions, 0, struct pw_permission); return pw_array_get_unchecked(&impl->permissions, 0, struct pw_permission);
} }

View file

@ -92,8 +92,8 @@ static struct pw_command *parse_command_help(const char *line, char **err)
return this; return this;
no_mem: no_mem:
asprintf(err, "no memory"); asprintf(err, "alloc failed: %m");
return NULL; return NULL;
} }
@ -128,12 +128,12 @@ static struct pw_command *parse_command_add_spa_lib(const char *line, char **err
return this; return this;
no_library: no_library:
asprintf(err, "%s requires <factory-regex> <library-name>", this->args[0]); asprintf(err, "%s requires <factory-regex> <library-name>", this->args[0]);
pw_free_strv(this->args); pw_free_strv(this->args);
return NULL; return NULL;
no_mem: no_mem:
asprintf(err, "no memory"); asprintf(err, "alloc failed: %m");
return NULL; return NULL;
} }
@ -168,12 +168,12 @@ static struct pw_command *parse_command_module_load(const char *line, char **err
return this; return this;
no_module: no_module:
asprintf(err, "%s requires a module name", this->args[0]); asprintf(err, "%s requires a module name", this->args[0]);
pw_free_strv(this->args); pw_free_strv(this->args);
return NULL; return NULL;
no_mem: no_mem:
asprintf(err, "no memory"); asprintf(err, "alloc failed: %m");
return NULL; return NULL;
} }
@ -212,12 +212,12 @@ static struct pw_command *parse_command_exec(const char *line, char **err)
return this; return this;
no_executable: no_executable:
asprintf(err, "requires an executable name"); asprintf(err, "requires an executable name");
pw_free_strv(this->args); pw_free_strv(this->args);
return NULL; return NULL;
no_mem: no_mem:
asprintf(err, "no memory"); asprintf(err, "alloc failed: %m");
return NULL; return NULL;
} }
@ -269,7 +269,7 @@ struct pw_command *pw_command_parse(const char *line, char **err)
} }
asprintf(err, "Command \"%s\" does not exist", name); asprintf(err, "Command \"%s\" does not exist", name);
out: out:
free(name); free(name);
return command; return command;
} }

View file

@ -53,12 +53,12 @@ pw_control_new(struct pw_core *core,
break; break;
default: default:
errno = -ENOTSUP; errno = -ENOTSUP;
goto exit; goto error_exit;
} }
impl = calloc(1, sizeof(struct impl) + user_data_size); impl = calloc(1, sizeof(struct impl) + user_data_size);
if (impl == NULL) if (impl == NULL)
goto exit; goto error_exit;
this = &impl->this; this = &impl->this;
this->id = id; this->id = id;
@ -86,7 +86,7 @@ pw_control_new(struct pw_core *core,
return this; return this;
exit: error_exit:
return NULL; return NULL;
} }
@ -223,8 +223,7 @@ int pw_control_add_link(struct pw_control *control, uint32_t cmix,
pw_control_emit_linked(control, other); pw_control_emit_linked(control, other);
pw_control_emit_linked(other, control); pw_control_emit_linked(other, control);
exit:
exit:
return res; return res;
} }

View file

@ -307,49 +307,51 @@ core_create_object(void *object,
factory = pw_core_find_factory(client->core, factory_name); factory = pw_core_find_factory(client->core, factory_name);
if (factory == NULL || factory->global == NULL) if (factory == NULL || factory->global == NULL)
goto no_factory; goto error_no_factory;
if (!PW_PERM_IS_R(pw_global_get_permissions(factory->global, client))) if (!PW_PERM_IS_R(pw_global_get_permissions(factory->global, client)))
goto no_factory; goto error_no_factory;
if (factory->info.type != type) if (factory->info.type != type)
goto wrong_type; goto error_type;
if (factory->info.version < version) if (factory->info.version < version)
goto wrong_version; goto error_version;
if (props) { if (props) {
properties = pw_properties_new_dict(props); properties = pw_properties_new_dict(props);
if (properties == NULL) if (properties == NULL)
goto no_properties; goto error_properties;
} else } else
properties = NULL; properties = NULL;
/* error will be posted */ /* error will be posted */
obj = pw_factory_create_object(factory, resource, type, version, properties, new_id); obj = pw_factory_create_object(factory, resource, type, version, properties, new_id);
if (obj == NULL) if (obj == NULL)
goto create_failed; goto error_create_failed;
return 0; return 0;
no_factory: error_no_factory:
res = -EINVAL; res = -ENOENT;
pw_log_error("can't find node factory %s", factory_name); pw_log_error("can't find node factory %s", factory_name);
pw_resource_error(resource, res, "unknown factory name %s", factory_name); pw_resource_error(resource, res, "unknown factory name %s", factory_name);
goto error; goto error_exit;
wrong_version: error_version:
wrong_type: error_type:
res = -EPROTO; res = -EPROTO;
pw_log_error("invalid resource type/version"); pw_log_error("invalid resource type/version");
pw_resource_error(resource, res, "wrong resource type/version"); pw_resource_error(resource, res, "wrong resource type/version");
goto error; goto error_exit;
no_properties: error_properties:
res = -errno; res = -errno;
pw_log_error("can't create properties"); pw_log_error("can't create properties: %m");
pw_resource_error(resource, res, "can't create properties: %s", spa_strerror(res)); pw_resource_error(resource, res, "can't create properties: %s", spa_strerror(res));
create_failed: goto error_exit;
error_create_failed:
res = -errno; res = -errno;
error: goto error_exit;
error_exit:
pw_map_insert_at(&client->objects, new_id, NULL); pw_map_insert_at(&client->objects, new_id, NULL);
pw_core_resource_remove_id(client->core_resource, new_id); pw_core_resource_remove_id(client->core_resource, new_id);
errno = -res; errno = -res;
@ -999,7 +1001,7 @@ int pw_core_find_format(struct pw_core *core,
} }
return res; return res;
error: error:
if (res == 0) if (res == 0)
res = -EBADF; res = -EBADF;
return res; return res;

View file

@ -481,12 +481,12 @@ static void device_add(struct pw_device *device, uint32_t id,
} }
if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
pw_log_error("can't get NODE interface: %d", res); pw_log_error("can't get NODE interface: %s", spa_strerror(res));
return; return;
} }
props = pw_properties_copy(device->properties); props = pw_properties_copy(device->properties);
if (info->props) if (info->props && props)
pw_properties_update(props, info->props); pw_properties_update(props, info->props);
node = pw_node_new(core, node = pw_node_new(core,

View file

@ -298,23 +298,25 @@ pw_global_bind(struct pw_global *global, struct pw_client *client, uint32_t perm
int res; int res;
if (global->version < version) if (global->version < version)
goto wrong_version; goto error_version;
if ((res = global->func(global->object, client, permissions, version, id)) < 0) if ((res = global->func(global->object, client, permissions, version, id)) < 0)
goto error; goto error_bind;
return res; return res;
wrong_version: error_version:
res = -EPROTO; res = -EPROTO;
pw_core_resource_errorf(client->core_resource, id, client->recv_seq, pw_core_resource_errorf(client->core_resource, id, client->recv_seq,
res, "id %d: interface version %d < %d", res, "id %d: interface version %d < %d",
id, global->version, version); id, global->version, version);
goto exit; goto error_exit;
error: error_bind:
pw_core_resource_errorf(client->core_resource, id, client->recv_seq, pw_core_resource_errorf(client->core_resource, id, client->recv_seq,
res, "can't bind global %u/%u: %d (%s)", id, version, res, spa_strerror(res)); res, "can't bind global %u/%u: %d (%s)", id, version, res, spa_strerror(res));
exit: goto error_exit;
error_exit:
pw_log_error("can't bind global %u/%u: %d (%s)", id, version, res, spa_strerror(res)); pw_log_error("can't bind global %u/%u: %d (%s)", id, version, res, spa_strerror(res));
pw_map_insert_at(&client->objects, id, NULL); pw_map_insert_at(&client->objects, id, NULL);
pw_core_resource_remove_id(client->core_resource, id); pw_core_resource_remove_id(client->core_resource, id);

View file

@ -359,7 +359,7 @@ static int do_negotiate(struct pw_link *this)
pw_log_debug("link %p: result %d", this, res); pw_log_debug("link %p: result %d", this, res);
return res; return res;
error: error:
pw_link_update_state(this, PW_LINK_STATE_ERROR, error); pw_link_update_state(this, PW_LINK_STATE_ERROR, error);
free(format); free(format);
return res; return res;
@ -742,7 +742,7 @@ static int do_allocation(struct pw_link *this)
} }
return 0; return 0;
error: error:
free_allocation(&output->allocation); free_allocation(&output->allocation);
free_allocation(&input->allocation); free_allocation(&input->allocation);
pw_link_update_state(this, PW_LINK_STATE_ERROR, error); pw_link_update_state(this, PW_LINK_STATE_ERROR, error);
@ -839,9 +839,9 @@ static void check_states(void *obj, void *user_data, int res, uint32_t id)
if ((res = do_allocation(this)) != 0) if ((res = do_allocation(this)) != 0)
goto exit; goto exit;
exit: exit:
if (SPA_RESULT_IS_ERROR(res)) { if (SPA_RESULT_IS_ERROR(res)) {
pw_log_debug("link %p: got error result %d", this, res); pw_log_debug("link %p: got error result %d (%s)", this, res, spa_strerror(res));
return; return;
} }

View file

@ -779,12 +779,14 @@ struct pw_node *pw_node_new(struct pw_core *core,
struct pw_node *this; struct pw_node *this;
size_t size; size_t size;
struct spa_system *data_system = core->data_system; struct spa_system *data_system = core->data_system;
char *n; char *n = NULL;
int res; int res;
impl = calloc(1, sizeof(struct impl) + user_data_size); impl = calloc(1, sizeof(struct impl) + user_data_size);
if (impl == NULL) if (impl == NULL) {
goto error; res = -errno;
goto error_exit;
}
if (name == NULL) if (name == NULL)
asprintf(&n, "node"); asprintf(&n, "node");
@ -802,7 +804,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
properties = pw_properties_new(NULL, NULL); properties = pw_properties_new(NULL, NULL);
if (properties == NULL) { if (properties == NULL) {
res = -errno; res = -errno;
goto clean_impl; goto error_clean;
} }
this->properties = properties; this->properties = properties;
@ -812,7 +814,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
this->source.fd = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); this->source.fd = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
if (this->source.fd == -1) { if (this->source.fd == -1) {
res = -errno; res = -errno;
goto clean_impl; goto error_clean;
} }
this->source.func = node_on_fd_events; this->source.func = node_on_fd_events;
@ -825,12 +827,12 @@ struct pw_node *pw_node_new(struct pw_core *core,
PW_MEMBLOCK_FLAG_SEAL, PW_MEMBLOCK_FLAG_SEAL,
size, size,
&this->activation)) < 0) &this->activation)) < 0)
goto clean_impl; goto error_clean;
impl->work = pw_work_queue_new(this->core->main_loop); impl->work = pw_work_queue_new(this->core->main_loop);
if (impl->work == NULL) { if (impl->work == NULL) {
res = -errno; res = -errno;
goto clean_impl; goto error_clean;
} }
this->info.name = n; this->info.name = n;
@ -872,14 +874,18 @@ struct pw_node *pw_node_new(struct pw_core *core,
return this; return this;
clean_impl: error_clean:
if (this->source.func != NULL) if (this->activation)
pw_memblock_free(this->activation);
if (this->source.fd != -1)
spa_system_close(this->core->data_system, this->source.fd); spa_system_close(this->core->data_system, this->source.fd);
if (n)
free(n);
free(impl);
error_exit:
if (properties) if (properties)
pw_properties_free(properties); pw_properties_free(properties);
free(impl);
errno = -res; errno = -res;
error:
return NULL; return NULL;
} }

View file

@ -96,10 +96,12 @@ open_plugin(struct registry *registry,
char *filename; char *filename;
void *hnd; void *hnd;
spa_handle_factory_enum_func_t enum_func; spa_handle_factory_enum_func_t enum_func;
int res = -EFAULT; int res;
if (asprintf(&filename, "%s/%s.so", path, lib) < 0) if (asprintf(&filename, "%s/%s.so", path, lib) < 0) {
goto out; res = -ENOMEM;
goto error_out;
}
if ((plugin = find_plugin(registry, filename)) != NULL) { if ((plugin = find_plugin(registry, filename)) != NULL) {
free(filename); free(filename);
@ -110,17 +112,17 @@ open_plugin(struct registry *registry,
if ((hnd = dlopen(filename, RTLD_NOW)) == NULL) { if ((hnd = dlopen(filename, RTLD_NOW)) == NULL) {
res = -ENOENT; res = -ENOENT;
fprintf(stderr, "can't load %s: %s\n", filename, dlerror()); fprintf(stderr, "can't load %s: %s\n", filename, dlerror());
goto out_free_filename; goto error_free_filename;
} }
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
res = -ESRCH; res = -ESRCH;
fprintf(stderr, "can't find enum function\n"); fprintf(stderr, "can't find enum function\n");
goto out_dlclose; goto error_dlclose;
} }
if ((plugin = calloc(1, sizeof(struct plugin))) == NULL) { if ((plugin = calloc(1, sizeof(struct plugin))) == NULL) {
res = -errno; res = -errno;
goto out_dlclose; goto error_dlclose;
} }
plugin->ref = 1; plugin->ref = 1;
@ -133,11 +135,11 @@ open_plugin(struct registry *registry,
return plugin; return plugin;
out_dlclose: error_dlclose:
dlclose(hnd); dlclose(hnd);
out_free_filename: error_free_filename:
free(filename); free(filename);
out: error_out:
errno = -res; errno = -res;
return NULL; return NULL;
} }
@ -170,8 +172,8 @@ static const struct spa_handle_factory *find_factory(struct plugin *plugin, cons
} }
res = -ENOENT; res = -ENOENT;
out: out:
fprintf(stderr, "can't find factory %s: %s", factory_name, spa_strerror(res));
errno = -res; errno = -res;
fprintf(stderr, "can't find factory %s: %m\n", factory_name);
return NULL; return NULL;
} }
@ -226,7 +228,7 @@ struct spa_handle *pw_load_spa_handle(const char *lib,
if (factory_name == NULL) { if (factory_name == NULL) {
res = -EINVAL; res = -EINVAL;
goto out; goto error_out;
} }
if (lib == NULL) if (lib == NULL)
@ -237,20 +239,20 @@ struct spa_handle *pw_load_spa_handle(const char *lib,
if ((plugin = open_plugin(sup->registry, sup->plugin_dir, lib)) == NULL) { if ((plugin = open_plugin(sup->registry, sup->plugin_dir, lib)) == NULL) {
res = -errno; res = -errno;
pw_log_warn("can't load '%s': %m", lib); pw_log_warn("can't load '%s': %m", lib);
goto out; goto error_out;
} }
factory = find_factory(plugin, factory_name); factory = find_factory(plugin, factory_name);
if (factory == NULL) { if (factory == NULL) {
res = -errno; res = -errno;
pw_log_warn("can't find factory '%s': %m %s", factory_name, spa_strerror(res)); pw_log_warn("can't find factory '%s': %m %s", factory_name, spa_strerror(res));
goto out_unref_plugin; goto error_unref_plugin;
} }
handle = calloc(1, sizeof(struct handle) + spa_handle_factory_get_size(factory, info)); handle = calloc(1, sizeof(struct handle) + spa_handle_factory_get_size(factory, info));
if (handle == NULL) { if (handle == NULL) {
res = -errno; res = -errno;
goto out; goto error_unref_plugin;
} }
if ((res = spa_handle_factory_init(factory, if ((res = spa_handle_factory_init(factory,
@ -258,7 +260,7 @@ struct spa_handle *pw_load_spa_handle(const char *lib,
support, n_support)) < 0) { support, n_support)) < 0) {
pw_log_warn("can't make factory instance '%s': %d (%s)", pw_log_warn("can't make factory instance '%s': %d (%s)",
factory_name, res, spa_strerror(res)); factory_name, res, spa_strerror(res));
goto out_free_handle; goto error_free_handle;
} }
handle->ref = 1; handle->ref = 1;
@ -268,11 +270,11 @@ struct spa_handle *pw_load_spa_handle(const char *lib,
return &handle->handle; return &handle->handle;
out_free_handle: error_free_handle:
free(handle); free(handle);
out_unref_plugin: error_unref_plugin:
unref_plugin(plugin); unref_plugin(plugin);
out: error_out:
errno = -res; errno = -res;
return NULL; return NULL;
} }

View file

@ -184,7 +184,7 @@ pw_properties_new_string(const char *str)
} }
return &impl->this; return &impl->this;
no_mem: no_mem:
pw_properties_free(&impl->this); pw_properties_free(&impl->this);
errno = -res; errno = -res;
return NULL; return NULL;

View file

@ -491,7 +491,7 @@ static int port_set_format(void *object,
p = add_param(stream, PARAM_TYPE_FORMAT, format); p = add_param(stream, PARAM_TYPE_FORMAT, format);
if (p == NULL) { if (p == NULL) {
res = -errno; res = -errno;
goto no_mem; goto error_exit;
} }
((struct spa_pod_object*)p->param)->body.id = SPA_PARAM_Format; ((struct spa_pod_object*)p->param)->body.id = SPA_PARAM_Format;
@ -517,7 +517,7 @@ static int port_set_format(void *object,
return 0; return 0;
no_mem: error_exit:
pw_stream_finish_format(stream, res, NULL, 0); pw_stream_finish_format(stream, res, NULL, 0);
return res; return res;
} }
@ -712,7 +712,7 @@ static int impl_node_process_input(void *object)
if (push_queue(impl, &impl->dequeued, b) == 0) if (push_queue(impl, &impl->dequeued, b) == 0)
call_process(impl); call_process(impl);
done: done:
copy_position(impl, impl->dequeued.incount); copy_position(impl, impl->dequeued.incount);
/* pop buffer to recycle */ /* pop buffer to recycle */
@ -735,7 +735,7 @@ static int impl_node_process_output(void *object)
int res; int res;
uint32_t index; uint32_t index;
again: again:
pw_log_trace("stream %p: process out %d %d %"PRIu64" %"PRIi64, stream, pw_log_trace("stream %p: process out %d %d %"PRIu64" %"PRIi64, stream,
io->status, io->buffer_id, impl->time.ticks, impl->time.delay); io->status, io->buffer_id, impl->time.ticks, impl->time.delay);
@ -962,7 +962,7 @@ static int handle_connect(struct pw_stream *stream)
impl->node = pw_node_new(impl->core, stream->name, impl->node = pw_node_new(impl->core, stream->name,
pw_properties_copy(stream->properties), 0); pw_properties_copy(stream->properties), 0);
if (impl->node == NULL) if (impl->node == NULL)
goto no_node; goto error_node;
impl->node_methods = impl_node; impl->node_methods = impl_node;
@ -986,7 +986,7 @@ static int handle_connect(struct pw_stream *stream)
stream->proxy = pw_remote_export(stream->remote, stream->proxy = pw_remote_export(stream->remote,
PW_TYPE_INTERFACE_Node, NULL, impl->node, 0); PW_TYPE_INTERFACE_Node, NULL, impl->node, 0);
if (stream->proxy == NULL) if (stream->proxy == NULL)
goto no_proxy; goto error_proxy;
pw_proxy_add_listener(stream->proxy, &stream->proxy_listener, &proxy_events, stream); pw_proxy_add_listener(stream->proxy, &stream->proxy_listener, &proxy_events, stream);
pw_node_proxy_add_listener((struct pw_node_proxy*)stream->proxy, pw_node_proxy_add_listener((struct pw_node_proxy*)stream->proxy,
@ -994,11 +994,11 @@ static int handle_connect(struct pw_stream *stream)
return 0; return 0;
no_node: error_node:
res = -errno; res = -errno;
pw_log_error("stream %p: can't make node: %m", stream); pw_log_error("stream %p: can't make node: %m", stream);
return res; return res;
no_proxy: error_proxy:
res = -errno; res = -errno;
pw_log_error("stream %p: can't make proxy: %m", stream); pw_log_error("stream %p: can't make proxy: %m", stream);
return res; return res;