diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-09-28 22:47:48 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-09-28 22:47:48 +0000 |
commit | 6f59ae1763ee48f27448a7de9d635f61886052e1 (patch) | |
tree | e83ab47226b6c716c200e9fa40f44668997eb642 /polyp/polyplib-context.c | |
parent | 450ad85b35bd600ed020f7ec119d51e7e7bc01a4 (diff) |
Add module-tunnel
add proper locking when autospawning a daemon
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@245 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/polyplib-context.c')
-rw-r--r-- | polyp/polyplib-context.c | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c index d793c186..d2fae0af 100644 --- a/polyp/polyplib-context.c +++ b/polyp/polyplib-context.c @@ -48,8 +48,10 @@ #include "xmalloc.h" #include "log.h" #include "client-conf.h" +#include "socket-util.h" #define DEFAULT_SERVER "/tmp/polypaudio/native" +#define AUTOSPAWN_LOCK "/tmp/polypaudio/autospawn.lock" static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = { [PA_COMMAND_REQUEST] = { pa_command_request }, @@ -347,38 +349,6 @@ finish: pa_context_unref(c); } -static struct sockaddr *resolve_server(const char *server, size_t *len) { - struct sockaddr *sa; - struct addrinfo hints, *result = NULL; - char *port, host[256]; - assert(server && len); - - snprintf(host, sizeof(host), "%s", server); - host[strcspn(host, ":")] = 0; - - if ((port = strrchr(server, ':'))) - port++; - - if (!port) - port = DEFAULT_PORT; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = 0; - - if (getaddrinfo(host, port, &hints, &result) != 0) - return NULL; - assert(result); - - sa = pa_xmalloc(*len = result->ai_addrlen); - memcpy(sa, result->ai_addr, *len); - - freeaddrinfo(result); - - return sa; -} - static int default_server_is_running(void) { struct stat st; @@ -499,9 +469,21 @@ int pa_context_connect(struct pa_context *c, const char *server, int spawn, cons if (!server) server = c->conf->default_server; - if (!server && spawn && c->conf->autospawn && !default_server_is_running()) - return context_connect_spawn(c, api); + if (!server && spawn && c->conf->autospawn) { + int lock_fd = pa_lock_lockfile(AUTOSPAWN_LOCK); + + if (!default_server_is_running()) { + int r = context_connect_spawn(c, api); + + if (lock_fd >= 0) + pa_unlock_lockfile(lock_fd); + return r; + } + if (lock_fd >= 0) + pa_unlock_lockfile(lock_fd); + } + if (!server) server = DEFAULT_SERVER; @@ -520,7 +502,7 @@ int pa_context_connect(struct pa_context *c, const char *server, int spawn, cons struct sockaddr* sa; size_t sa_len; - if (!(sa = resolve_server(server, &sa_len))) { + if (!(sa = pa_resolve_server(server, &sa_len, PA_NATIVE_DEFAULT_PORT))) { pa_context_fail(c, PA_ERROR_INVALIDSERVER); goto finish; } |