]> code.delx.au - pulseaudio/blobdiff - src/pulse/context.c
Make the shared memory segment size configurable
[pulseaudio] / src / pulse / context.c
index f9f021af08a09423eb3b492444bbbe0c8c96e438..3145d9c80ccdd18ca96c6da6c23faa03b8700bd2 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -55,6 +53,7 @@
 #include <pulse/xmalloc.h>
 #include <pulse/utf8.h>
 #include <pulse/util.h>
+#include <pulse/i18n.h>
 
 #include <pulsecore/winsock.h>
 #include <pulsecore/core-error.h>
@@ -70,6 +69,7 @@
 #include <pulsecore/socket-util.h>
 #include <pulsecore/creds.h>
 #include <pulsecore/macro.h>
+#include <pulsecore/proplist-util.h>
 
 #include "internal.h"
 
@@ -81,7 +81,7 @@
 
 #include "context.h"
 
-#define AUTOSPAWN_LOCK "autospawn.lock"
+void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
 
 static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
     [PA_COMMAND_REQUEST] = pa_command_request,
@@ -94,23 +94,9 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
     [PA_COMMAND_PLAYBACK_STREAM_SUSPENDED] = pa_command_stream_suspended,
     [PA_COMMAND_RECORD_STREAM_SUSPENDED] = pa_command_stream_suspended,
     [PA_COMMAND_STARTED] = pa_command_stream_started,
-    [PA_COMMAND_SUBSCRIBE_EVENT] = pa_command_subscribe_event
+    [PA_COMMAND_SUBSCRIBE_EVENT] = pa_command_subscribe_event,
+    [PA_COMMAND_EXTENSION] = pa_command_extension
 };
-
-static void unlock_autospawn_lock_file(pa_context *c) {
-    pa_assert(c);
-
-    if (c->autospawn_lock_fd >= 0) {
-        char *lf;
-
-        lf = pa_runtime_path(AUTOSPAWN_LOCK);
-        pa_unlock_lockfile(lf, c->autospawn_lock_fd);
-        pa_xfree(lf);
-
-        c->autospawn_lock_fd = -1;
-    }
-}
-
 static void context_free(pa_context *c);
 
 pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) {
@@ -125,6 +111,9 @@ static void reset_callbacks(pa_context *c) {
 
     c->subscribe_callback = NULL;
     c->subscribe_userdata = NULL;
+
+    c->ext_stream_restore.callback = NULL;
+    c->ext_stream_restore.userdata = NULL;
 }
 
 pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) {
@@ -132,6 +121,8 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
 
     pa_assert(mainloop);
 
+    pa_init_i18n();
+
     if (!name && !pa_proplist_contains(p, PA_PROP_APPLICATION_NAME))
         return NULL;
 
@@ -164,9 +155,11 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
     c->is_local = FALSE;
     c->server_list = NULL;
     c->server = NULL;
-    c->autospawn_lock_fd = -1;
-    memset(&c->spawn_api, 0, sizeof(c->spawn_api));
+
+    c->do_shm = FALSE;
+
     c->do_autospawn = FALSE;
+    memset(&c->spawn_api, 0, sizeof(c->spawn_api));
 
 #ifndef MSG_NOSIGNAL
 #ifdef SIGPIPE
@@ -175,16 +168,16 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
 #endif
 
     c->conf = pa_client_conf_new();
-    pa_client_conf_load(c->conf, NULL);
 #ifdef HAVE_X11
     pa_client_conf_from_x11(c->conf, NULL);
 #endif
+    pa_client_conf_load(c->conf, NULL);
     pa_client_conf_env(c->conf);
 
-    if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm))) {
+    if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) {
 
         if (!c->conf->disable_shm)
-            c->mempool = pa_mempool_new(0);
+            c->mempool = pa_mempool_new(FALSE, c->conf->shm_size);
 
         if (!c->mempool) {
             context_free(c);
@@ -235,8 +228,6 @@ static void context_free(pa_context *c) {
 
     context_unlink(c);
 
-    unlock_autospawn_lock_file(c);
-
     if (c->record_streams)
         pa_dynarray_free(c->record_streams, NULL, NULL);
     if (c->playback_streams)
@@ -396,11 +387,11 @@ int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa
         err = PA_ERR_UNKNOWN;
 
     if (fail) {
-        pa_context_fail(c, err);
+        pa_context_fail(c, (int) err);
         return -1;
     }
 
-    pa_context_set_error(c, err);
+    pa_context_set_error(c, (int) err);
 
     return 0;
 }
@@ -422,6 +413,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
     switch(c->state) {
         case PA_CONTEXT_AUTHORIZING: {
             pa_tagstruct *reply;
+            pa_bool_t shm_on_remote = FALSE;
 
             if (pa_tagstruct_getu32(t, &c->version) < 0 ||
                 !pa_tagstruct_eof(t)) {
@@ -435,10 +427,22 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
                 goto finish;
             }
 
+            /* Starting with protocol version 13 the MSB of the version
+               tag reflects if shm is available for this connection or
+               not. */
+            if (c->version >= 13) {
+                shm_on_remote = !!(c->version & 0x80000000U);
+                c->version &= 0x7FFFFFFFU;
+            }
+
+            pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION);
+
             /* Enable shared memory support if possible */
-            if (c->version >= 10 &&
-                pa_mempool_is_shared(c->mempool) &&
-                c->is_local) {
+            if (c->do_shm)
+                if (c->version < 10 || (c->version >= 13 && !shm_on_remote))
+                    c->do_shm = FALSE;
+
+            if (c->do_shm) {
 
                 /* Only enable SHM if both sides are owned by the same
                  * user. This is a security measure because otherwise
@@ -446,12 +450,14 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
 
 #ifdef HAVE_CREDS
                 const pa_creds *creds;
-                if ((creds = pa_pdispatch_creds(pd)))
-                    if (getuid() == creds->uid)
-                        pa_pstream_enable_shm(c->pstream, TRUE);
+                if (!(creds = pa_pdispatch_creds(pd)) || getuid() != creds->uid)
+                    c->do_shm = FALSE;
 #endif
             }
 
+            pa_log_debug("Negotiated SHM: %s", pa_yes_no(c->do_shm));
+            pa_pstream_enable_shm(c->pstream, c->do_shm);
+
             reply = pa_tagstruct_command(c, PA_COMMAND_SET_CLIENT_NAME, &tag);
 
             if (c->version >= 13) {
@@ -507,10 +513,19 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
     c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX);
 
     if (!c->conf->cookie_valid)
-        pa_log_info("No cookie loaded. Attempting to connect without.");
+        pa_log_info(_("No cookie loaded. Attempting to connect without."));
 
     t = pa_tagstruct_command(c, PA_COMMAND_AUTH, &tag);
-    pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION);
+
+    c->do_shm =
+        pa_mempool_is_shared(c->mempool) &&
+        c->is_local;
+
+    pa_log_debug("SHM possible: %s", pa_yes_no(c->do_shm));
+
+    /* Starting with protocol version 13 we use the MSB of the version
+     * tag for informing the other side if we could do SHM or not */
+    pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION | (c->do_shm ? 0x80000000U : 0));
     pa_tagstruct_put_arbitrary(t, c->conf->cookie, sizeof(c->conf->cookie));
 
 #ifdef HAVE_CREDS
@@ -536,37 +551,95 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
     pa_context_unref(c);
 }
 
-static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata);
+static char *get_old_legacy_runtime_dir(void) {
+    char *p, u[128];
+    struct stat st;
 
-#ifndef OS_IS_WIN32
+    if (!pa_get_user_name(u, sizeof(u)))
+        return NULL;
 
-static int context_connect_spawn(pa_context *c) {
-    pid_t pid;
-    int status, r;
-    int fds[2] = { -1, -1} ;
-    pa_iochannel *io;
+    p = pa_sprintf_malloc("/tmp/pulse-%s", u);
 
-    if (getuid() == 0)
-        return -1;
+    if (stat(p, &st) < 0) {
+        pa_xfree(p);
+        return NULL;
+    }
 
-    pa_context_ref(c);
+    if (st.st_uid != getuid()) {
+        pa_xfree(p);
+        return NULL;
+    }
 
-    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
-        pa_log_error("socketpair(): %s", pa_cstrerror(errno));
-        pa_context_fail(c, PA_ERR_INTERNAL);
-        goto fail;
+    return p;
+}
+
+static char *get_very_old_legacy_runtime_dir(void) {
+    char *p, h[128];
+    struct stat st;
+
+    if (!pa_get_home_dir(h, sizeof(h)))
+        return NULL;
+
+    p = pa_sprintf_malloc("%s/.pulse", h);
+
+    if (stat(p, &st) < 0) {
+        pa_xfree(p);
+        return NULL;
+    }
+
+    if (st.st_uid != getuid()) {
+        pa_xfree(p);
+        return NULL;
+    }
+
+    return p;
+}
+
+
+static pa_strlist *prepend_per_user(pa_strlist *l) {
+    char *ufn;
+    static char *legacy_dir;
+
+    /* The very old per-user instance path (< 0.9.11). This is supported only to ease upgrades */
+    if ((legacy_dir = get_very_old_legacy_runtime_dir())) {
+        char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir);
+        l = pa_strlist_prepend(l, p);
+        pa_xfree(p);
+        pa_xfree(legacy_dir);
     }
 
-    pa_make_fd_cloexec(fds[0]);
+    /* The old per-user instance path (< 0.9.12). This is supported only to ease upgrades */
+    if ((legacy_dir = get_old_legacy_runtime_dir())) {
+        char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir);
+        l = pa_strlist_prepend(l, p);
+        pa_xfree(p);
+        pa_xfree(legacy_dir);
+    }
 
-    pa_make_socket_low_delay(fds[0]);
-    pa_make_socket_low_delay(fds[1]);
+    /* The per-user instance */
+    if ((ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET))) {
+        l = pa_strlist_prepend(l, ufn);
+        pa_xfree(ufn);
+    }
+
+    return l;
+}
+
+#ifndef OS_IS_WIN32
+
+static int context_autospawn(pa_context *c) {
+    pid_t pid;
+    int status, r;
+
+    pa_log_debug("Trying to autospawn...");
+
+    pa_context_ref(c);
 
     if (c->spawn_api.prefork)
         c->spawn_api.prefork();
 
     if ((pid = fork()) < 0) {
-        pa_log_error("fork(): %s", pa_cstrerror(errno));
+        pa_log_error(_("fork(): %s"), pa_cstrerror(errno));
         pa_context_fail(c, PA_ERR_INTERNAL);
 
         if (c->spawn_api.postfork)
@@ -576,31 +649,22 @@ static int context_connect_spawn(pa_context *c) {
     } else if (!pid) {
         /* Child */
 
-        char t[128];
         const char *state = NULL;
 #define MAX_ARGS 64
         const char * argv[MAX_ARGS+1];
         int n;
-        char *f;
-
-        pa_close_all(fds[1], -1);
-
-        f = pa_sprintf_malloc("%i", fds[1]);
-        pa_set_env("PULSE_PASSED_FD", f);
-        pa_xfree(f);
 
         if (c->spawn_api.atfork)
             c->spawn_api.atfork();
 
+        pa_close_all(-1);
+
         /* Setup argv */
 
         n = 0;
 
         argv[n++] = c->conf->daemon_binary;
-        argv[n++] = "--daemonize=yes";
-
-        pa_snprintf(t, sizeof(t), "-Lmodule-native-protocol-fd fd=%i", fds[1]);
-        argv[n++] = strdup(t);
+        argv[n++] = "--start";
 
         while (n < MAX_ARGS) {
             char *a;
@@ -620,15 +684,15 @@ static int context_connect_spawn(pa_context *c) {
 
     /* Parent */
 
-    pa_assert_se(pa_close(fds[1]) == 0);
-
-    r = waitpid(pid, &status, 0);
-
     if (c->spawn_api.postfork)
         c->spawn_api.postfork();
 
+    do {
+        r = waitpid(pid, &status, 0);
+    } while (r < 0 && errno == EINTR);
+
     if (r < 0) {
-        pa_log("waitpid(): %s", pa_cstrerror(errno));
+        pa_log(_("waitpid(): %s"), pa_cstrerror(errno));
         pa_context_fail(c, PA_ERR_INTERNAL);
         goto fail;
     } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
@@ -636,21 +700,11 @@ static int context_connect_spawn(pa_context *c) {
         goto fail;
     }
 
-    c->is_local = TRUE;
-
-    unlock_autospawn_lock_file(c);
-
-    io = pa_iochannel_new(c->mainloop, fds[0], fds[0]);
-    setup_context(c, io);
-
     pa_context_unref(c);
 
     return 0;
 
 fail:
-    pa_close_pipe(fds);
-
-    unlock_autospawn_lock_file(c);
 
     pa_context_unref(c);
 
@@ -659,6 +713,8 @@ fail:
 
 #endif /* OS_IS_WIN32 */
 
+static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata);
+
 static int try_next_connection(pa_context *c) {
     char *u = NULL;
     int r = -1;
@@ -676,8 +732,18 @@ static int try_next_connection(pa_context *c) {
 
 #ifndef OS_IS_WIN32
             if (c->do_autospawn) {
-                r = context_connect_spawn(c);
-                goto finish;
+
+                if ((r = context_autospawn(c)) < 0)
+                    goto finish;
+
+                /* Autospawn only once */
+                c->do_autospawn = FALSE;
+
+                /* Connect only to per-user sockets this time */
+                c->server_list = prepend_per_user(c->server_list);
+
+                /* Retry connection */
+                continue;
             }
 #endif
 
@@ -732,32 +798,12 @@ static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userd
         goto finish;
     }
 
-    unlock_autospawn_lock_file(c);
     setup_context(c, io);
 
 finish:
     pa_context_unref(c);
 }
 
-
-static char *get_legacy_runtime_dir(void) {
-    char *p, u[128];
-    struct stat st;
-
-    if (!pa_get_user_name(u, sizeof(u)))
-        return NULL;
-
-    p = pa_sprintf_malloc("/tmp/pulse-%s", u);
-
-    if (stat(p, &st) < 0)
-        return NULL;
-
-    if (st.st_uid != getuid())
-        return NULL;
-
-    return p;
-}
-
 int pa_context_connect(
         pa_context *c,
         const char *server,
@@ -785,12 +831,13 @@ int pa_context_connect(
             pa_context_fail(c, PA_ERR_INVALIDSERVER);
             goto finish;
         }
+
     } else {
-        char *d, *ufn;
-        static char *legacy_dir;
+        char *d;
 
         /* Prepend in reverse order */
 
+        /* Follow the X display */
         if ((d = getenv("DISPLAY"))) {
             char *e;
             d = pa_xstrdup(d);
@@ -803,37 +850,27 @@ int pa_context_connect(
             pa_xfree(d);
         }
 
-        c->server_list = pa_strlist_prepend(c->server_list, "tcp6:localhost");
-        c->server_list = pa_strlist_prepend(c->server_list, "tcp4:localhost");
+        /* Add TCP/IP on the localhost */
+        c->server_list = pa_strlist_prepend(c->server_list, "tcp6:[::1]");
+        c->server_list = pa_strlist_prepend(c->server_list, "tcp4:127.0.0.1");
 
-        /* The system wide instance */
+        /* The system wide instance via PF_LOCAL */
         c->server_list = pa_strlist_prepend(c->server_list, PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET);
 
-        /* The old per-user instance path. This is supported only to easy upgrades */
-        if ((legacy_dir = get_legacy_runtime_dir())) {
-            char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir);
-            c->server_list = pa_strlist_prepend(c->server_list, p);
-            pa_xfree(p);
-            pa_xfree(legacy_dir);
-        }
-
-        /* The per-user instance */
-        c->server_list = pa_strlist_prepend(c->server_list, ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET));
-        pa_xfree(ufn);
+        /* The user instance via PF_LOCAL */
+        c->server_list = prepend_per_user(c->server_list);
 
-        /* Wrap the connection attempts in a single transaction for sane autospawn locking */
+        /* Set up autospawning */
         if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) {
-            char *lf;
 
-            lf = pa_runtime_path(AUTOSPAWN_LOCK);
-            pa_assert(c->autospawn_lock_fd <= 0);
-            c->autospawn_lock_fd = pa_lock_lockfile(lf);
-            pa_xfree(lf);
+            if (getuid() == 0)
+                pa_log_debug("Not doing autospawn since we are root.");
+            else {
+                c->do_autospawn = TRUE;
 
-            if (api)
-                c->spawn_api = *api;
-
-            c->do_autospawn = TRUE;
+                if (api)
+                    c->spawn_api = *api;
+            }
         }
     }
 
@@ -892,11 +929,11 @@ int pa_context_is_pending(pa_context *c) {
 
 static void set_dispatch_callbacks(pa_operation *o);
 
-static void pdispatch_drain_callback(PA_GCC_UNUSED pa_pdispatch*pd, void *userdata) {
+static void pdispatch_drain_callback(pa_pdispatch*pd, void *userdata) {
     set_dispatch_callbacks(userdata);
 }
 
-static void pstream_drain_callback(PA_GCC_UNUSED pa_pstream *s, void *userdata) {
+static void pstream_drain_callback(pa_pstream *s, void *userdata) {
     set_dispatch_callbacks(userdata);
 }
 
@@ -948,7 +985,7 @@ pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *u
     return o;
 }
 
-void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
     pa_operation *o = userdata;
     int success = 1;
 
@@ -1100,7 +1137,7 @@ const char* pa_context_get_server(pa_context *c) {
     return c->server;
 }
 
-uint32_t pa_context_get_protocol_version(PA_GCC_UNUSED pa_context *c) {
+uint32_t pa_context_get_protocol_version(pa_context *c) {
     return PA_PROTOCOL_VERSION;
 }
 
@@ -1194,84 +1231,30 @@ pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[]
     return o;
 }
 
-void pa_init_proplist(pa_proplist *p) {
-    int a, b;
-#ifndef HAVE_DECL_ENVIRON
-    extern char **environ;
-#endif
-    char **e;
-
-    pa_assert(p);
-
-    for (e = environ; *e; e++) {
-
-        if (pa_startswith(*e, "PULSE_PROP_")) {
-            size_t kl = strcspn(*e+11, "=");
-            char *k;
-
-            if ((*e)[11+kl] != '=')
-                continue;
-
-            if (!pa_utf8_valid(*e+11+kl+1))
-                continue;
-
-            k = pa_xstrndup(*e+11, kl);
-
-            if (pa_proplist_contains(p, k)) {
-                pa_xfree(k);
-                continue;
-            }
-
-            pa_proplist_sets(p, k, *e+11+kl+1);
-            pa_xfree(k);
-        }
-    }
-
-    if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_ID)) {
-        char t[32];
-        pa_snprintf(t, sizeof(t), "%lu", (unsigned long) getpid());
-        pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_ID, t);
-    }
-
-    if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_USER)) {
-        char t[64];
-        if (pa_get_user_name(t, sizeof(t))) {
-            char *c = pa_utf8_filter(t);
-            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, c);
-            pa_xfree(c);
-        }
-    }
-
-    if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_HOST)) {
-        char t[64];
-        if (pa_get_host_name(t, sizeof(t))) {
-            char *c = pa_utf8_filter(t);
-            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, c);
-            pa_xfree(c);
-        }
-    }
-
-    a = pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY);
-    b = pa_proplist_contains(p, PA_PROP_APPLICATION_NAME);
+void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+    pa_context *c = userdata;
+    uint32_t idx;
+    const char *name;
 
-    if (!a || !b) {
-        char t[PATH_MAX];
-        if (pa_get_binary_name(t, sizeof(t))) {
-            char *c = pa_utf8_filter(t);
+    pa_assert(pd);
+    pa_assert(command == PA_COMMAND_EXTENSION);
+    pa_assert(t);
+    pa_assert(c);
+    pa_assert(PA_REFCNT_VALUE(c) >= 1);
 
-            if (!a)
-                pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
-            if (!b)
-                pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, c);
+    pa_context_ref(c);
 
-            pa_xfree(c);
-        }
+    if (pa_tagstruct_getu32(t, &idx) < 0 ||
+        pa_tagstruct_gets(t, &name) < 0) {
+        pa_context_fail(c, PA_ERR_PROTOCOL);
+        goto finish;
     }
 
-    if (!pa_proplist_contains(p, PA_PROP_APPLICATION_LANGUAGE)) {
-        const char *l;
+    if (!strcmp(name, "module-stream-restore"))
+        pa_ext_stream_restore_command(c, tag, t);
+    else
+        pa_log(_("Received message for unknown extension '%s'"), name);
 
-        if ((l = setlocale(LC_MESSAGES, NULL)))
-            pa_proplist_sets(p, PA_PROP_APPLICATION_LANGUAGE, l);
-    }
+finish:
+    pa_context_unref(c);
 }