summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/common.c b/src/common.c
index 6e38c94..80be86c 100644
--- a/src/common.c
+++ b/src/common.c
@@ -36,6 +36,7 @@
int ca_context_create(ca_context **_c) {
ca_context *c;
int ret;
+ const char *d;
ca_return_val_if_fail(_c, CA_ERROR_INVALID);
@@ -43,16 +44,29 @@ int ca_context_create(ca_context **_c) {
return CA_ERROR_OOM;
if (!(c->mutex = ca_mutex_new())) {
- ca_free(c);
+ ca_context_destroy(c);
return CA_ERROR_OOM;
}
if ((ret = ca_proplist_create(&c->props)) < 0) {
- ca_mutex_free(c->mutex);
- ca_free(c);
+ ca_context_destroy(c);
return ret;
}
+ if ((d = getenv("CANBERRA_DRIVER"))) {
+ if ((ret = ca_context_set_driver(c, d)) < 0) {
+ ca_context_destroy(c);
+ return ret;
+ }
+ }
+
+ if ((d = getenv("CANBERRA_DEVICE"))) {
+ if ((ret = ca_context_change_device(c, d)) < 0) {
+ ca_context_destroy(c);
+ return ret;
+ }
+ }
+
*_c = c;
return CA_SUCCESS;
}
@@ -72,7 +86,9 @@ int ca_context_destroy(ca_context *c) {
if (c->props)
ca_assert_se(ca_proplist_destroy(c->props) == CA_SUCCESS);
- ca_mutex_free(c->mutex);
+ if (c->mutex)
+ ca_mutex_free(c->mutex);
+
ca_free(c->driver);
ca_free(c->device);
ca_free(c);