[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.16-test3-12-g2778220
Lennart Poettering
gitmailer-noreply at 0pointer.de
Fri Jul 31 18:11:21 PDT 2009
This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.
The master branch has been updated
from 0113e7282cc5c0131f9f681b84459fcdf2e806c4 (commit)
- Log -----------------------------------------------------------------
2778220 autospawn: if creating the lock file fails, pass error code cleanly back to main process
49fd8ee core-util: replace remaining fixed size destination string functions by _malloc() versions
c6ea9fe core-util: rework pa_strlcpy() to not rely on strncpy()
e5c2256 pipe: replace PIPE_BUF macro pa pa_pipe_buf call
-----------------------------------------------------------------------
Summary of changes:
src/modules/module-pipe-sink.c | 6 +-
src/modules/module-pipe-source.c | 2 +-
src/pulsecore/authkey.c | 37 +++++++-------
src/pulsecore/core-scache.c | 5 +-
src/pulsecore/core-util.c | 102 +++++++++++++++++++++++++++++++++-----
src/pulsecore/core-util.h | 5 ++
src/pulsecore/lock-autospawn.c | 66 +++++++++++++++++--------
src/pulsecore/proplist-util.c | 6 ++-
src/tests/get-binary-name-test.c | 25 +++++++++-
src/utils/padsp.c | 8 ++-
10 files changed, 197 insertions(+), 65 deletions(-)
-----------------------------------------------------------------------
commit e5c2256e360df3662295b8cc0594568e425e8679
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Aug 1 01:59:58 2009 +0200
pipe: replace PIPE_BUF macro pa pa_pipe_buf call
This should help portability to platforms that lack PIPE_BUF. Based on a
patch from Samuel Thibault.
See ticket #546
diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c
index 8a7dc84..9c16932 100644
--- a/src/modules/module-pipe-sink.c
+++ b/src/modules/module-pipe-sink.c
@@ -122,7 +122,7 @@ static int process_render(struct userdata *u) {
pa_assert(u);
if (u->memchunk.length <= 0)
- pa_sink_render(u->sink, PIPE_BUF, &u->memchunk);
+ pa_sink_render(u->sink, pa_pipe_buf(u->fd), &u->memchunk);
pa_assert(u->memchunk.length > 0);
@@ -299,8 +299,8 @@ int pa__init(pa_module*m) {
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
pa_sink_set_rtpoll(u->sink, u->rtpoll);
- pa_sink_set_max_request(u->sink, PIPE_BUF);
- pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(PIPE_BUF, &u->sink->sample_spec));
+ pa_sink_set_max_request(u->sink, pa_pipe_buf(u->fd));
+ pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(pa_pipe_buf(u->fd), &u->sink->sample_spec));
u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c
index e5609fb..49104f8 100644
--- a/src/modules/module-pipe-source.c
+++ b/src/modules/module-pipe-source.c
@@ -142,7 +142,7 @@ static void thread_func(void *userdata) {
void *p;
if (!u->memchunk.memblock) {
- u->memchunk.memblock = pa_memblock_new(u->core->mempool, PIPE_BUF);
+ u->memchunk.memblock = pa_memblock_new(u->core->mempool, pa_pipe_buf(u->fd));
u->memchunk.index = u->memchunk.length = 0;
}
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 5f777d5..d01efa2 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2779,3 +2779,19 @@ char* pa_maybe_prefix_path(const char *path, const char *prefix) {
return pa_sprintf_malloc("%s" PA_PATH_SEP "%s", prefix, path);
}
+
+size_t pa_pipe_buf(int fd) {
+
+#ifdef _PC_PIPE_BUF
+ long n;
+
+ if ((n = fpathconf(fd, _PC_PIPE_BUF)) >= 0)
+ return (size_t) n;
+#endif
+
+#ifdef PIPE_BUF
+ return PIPE_BUF;
+#else
+ return 4096;
+#endif
+}
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 96a0480..b5e8453 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -236,4 +236,7 @@ char **pa_split_spaces_strv(const char *s);
char* pa_maybe_prefix_path(const char *path, const char *prefix);
+/* Returns size of the specified pipe or 4096 on failure */
+size_t pa_pipe_buf(int fd);
+
#endif
commit c6ea9fecc9acd70642ae45b01300484f6b900c6b
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Aug 1 02:01:58 2009 +0200
core-util: rework pa_strlcpy() to not rely on strncpy()
strncpy() is very slow since it resets the entire destination buffer.
Replace usage of strncpy by memcpy().
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index d01efa2..99644d7 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -552,12 +552,20 @@ char *pa_vsprintf_malloc(const char *format, va_list ap) {
/* Similar to OpenBSD's strlcpy() function */
char *pa_strlcpy(char *b, const char *s, size_t l) {
+ size_t k;
+
pa_assert(b);
pa_assert(s);
pa_assert(l > 0);
- strncpy(b, s, l);
- b[l-1] = 0;
+ k = strlen(s);
+
+ if (k > l-1)
+ k = l-1;
+
+ memcpy(b, s, k);
+ b[k] = 0;
+
return b;
}
commit 49fd8ee72e76cd27a978a843ecc58ad10fe077bc
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Aug 1 02:03:22 2009 +0200
core-util: replace remaining fixed size destination string functions by _malloc() versions
This helps portability to GNU/Hurd.
Patch originally from Samuel Thibault but modified.
Closes ticket #546
diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index 1e31d07..15613e2 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <pulse/util.h>
+#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
@@ -147,47 +148,46 @@ int pa_authkey_load(const char *path, void *data, size_t length) {
/* If the specified file path starts with / return it, otherwise
* return path prepended with home directory */
-static const char *normalize_path(const char *fn, char *s, size_t l) {
+static char *normalize_path(const char *fn) {
pa_assert(fn);
- pa_assert(s);
- pa_assert(l > 0);
#ifndef OS_IS_WIN32
if (fn[0] != '/') {
#else
if (strlen(fn) < 3 || !isalpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
#endif
- char homedir[PATH_MAX];
+ char *homedir, *s;
- if (!pa_get_home_dir(homedir, sizeof(homedir)))
+ if (!(homedir = pa_get_home_dir_malloc()))
return NULL;
-#ifndef OS_IS_WIN32
- pa_snprintf(s, l, "%s/%s", homedir, fn);
-#else
- pa_snprintf(s, l, "%s\\%s", homedir, fn);
-#endif
+ s = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", homedir, fn);
+ pa_xfree(homedir);
+
return s;
}
- return fn;
+ return pa_xstrdup(fn);
}
/* Load a cookie from a file in the home directory. If the specified
* path starts with /, use it as absolute path instead. */
int pa_authkey_load_auto(const char *fn, void *data, size_t length) {
- char path[PATH_MAX];
- const char *p;
+ char *p;
+ int ret;
pa_assert(fn);
pa_assert(data);
pa_assert(length > 0);
- if (!(p = normalize_path(fn, path, sizeof(path))))
+ if (!(p = normalize_path(fn)))
return -2;
- return pa_authkey_load(p, data, length);
+ ret = pa_authkey_load(p, data, length);
+ pa_xfree(p);
+
+ return ret;
}
/* Store the specified cookie in the specified cookie file */
@@ -195,14 +195,13 @@ int pa_authkey_save(const char *fn, const void *data, size_t length) {
int fd = -1;
int unlock = 0, ret = -1;
ssize_t r;
- char path[PATH_MAX];
- const char *p;
+ char *p;
pa_assert(fn);
pa_assert(data);
pa_assert(length > 0);
- if (!(p = normalize_path(fn, path, sizeof(path))))
+ if (!(p = normalize_path(fn)))
return -2;
if ((fd = open(p, O_RDWR|O_CREAT|O_NOCTTY, S_IRUSR|S_IWUSR)) < 0) {
@@ -232,5 +231,7 @@ finish:
}
}
+ pa_xfree(p);
+
return ret;
}
diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c
index 4c5a4b2..fde12ec 100644
--- a/src/pulsecore/core-scache.c
+++ b/src/pulsecore/core-scache.c
@@ -494,13 +494,14 @@ int pa_scache_add_directory_lazy(pa_core *c, const char *pathname) {
struct dirent *e;
while ((e = readdir(dir))) {
- char p[PATH_MAX];
+ char *p;
if (e->d_name[0] == '.')
continue;
- pa_snprintf(p, sizeof(p), "%s/%s", pathname, e->d_name);
+ p = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", pathname, e->d_name);
add_file(c, p);
+ pa_xfree(p);
}
closedir(dir);
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 99644d7..d4baf69 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1336,26 +1336,32 @@ int pa_unlock_lockfile(const char *fn, int fd) {
}
static char *get_pulse_home(void) {
- char h[PATH_MAX];
+ char *h;
struct stat st;
+ char *ret = NULL;
- if (!pa_get_home_dir(h, sizeof(h))) {
+ if (!(h = pa_get_home_dir_malloc())) {
pa_log_error("Failed to get home directory.");
return NULL;
}
if (stat(h, &st) < 0) {
pa_log_error("Failed to stat home directory %s: %s", h, pa_cstrerror(errno));
- return NULL;
+ goto finish;
}
if (st.st_uid != getuid()) {
pa_log_error("Home directory %s not ours.", h);
errno = EACCES;
- return NULL;
+ goto finish;
}
- return pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
+ ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
+
+finish:
+ pa_xfree(h);
+
+ return ret;
}
char *pa_get_state_dir(void) {
@@ -1380,6 +1386,50 @@ char *pa_get_state_dir(void) {
return d;
}
+char *pa_get_home_dir_malloc(void) {
+ char *homedir;
+ size_t allocated = 128;
+
+ for (;;) {
+ homedir = pa_xmalloc(allocated);
+
+ if (!pa_get_home_dir(homedir, allocated)) {
+ pa_xfree(homedir);
+ return NULL;
+ }
+
+ if (strlen(homedir) < allocated - 1)
+ break;
+
+ pa_xfree(homedir);
+ allocated *= 2;
+ }
+
+ return homedir;
+}
+
+char *pa_get_binary_name_malloc(void) {
+ char *t;
+ size_t allocated = 128;
+
+ for (;;) {
+ t = pa_xmalloc(allocated);
+
+ if (!pa_get_binary_name(t, allocated)) {
+ pa_xfree(t);
+ return NULL;
+ }
+
+ if (strlen(t) < allocated - 1)
+ break;
+
+ pa_xfree(t);
+ allocated *= 2;
+ }
+
+ return t;
+}
+
static char* make_random_dir(mode_t m) {
static const char table[] =
"abcdefghijklmnopqrstuvwxyz"
@@ -1634,14 +1684,15 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
if (local) {
const char *e;
char *lfn;
- char h[PATH_MAX];
+ char *h;
FILE *f;
if ((e = getenv("PULSE_CONFIG_PATH")))
fn = lfn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", e, local);
- else if (pa_get_home_dir(h, sizeof(h)))
+ else if ((h = pa_get_home_dir_malloc())) {
fn = lfn = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse" PA_PATH_SEP "%s", h, local);
- else
+ pa_xfree(h);
+ } else
return NULL;
#ifdef OS_IS_WIN32
@@ -1721,13 +1772,14 @@ char *pa_find_config_file(const char *global, const char *local, const char *env
if (local) {
const char *e;
char *lfn;
- char h[PATH_MAX];
+ char *h;
if ((e = getenv("PULSE_CONFIG_PATH")))
fn = lfn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", e, local);
- else if (pa_get_home_dir(h, sizeof(h)))
+ else if ((h = pa_get_home_dir_malloc())) {
fn = lfn = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse" PA_PATH_SEP "%s", h, local);
- else
+ pa_xfree(h);
+ } else
return NULL;
#ifdef OS_IS_WIN32
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index b5e8453..6de4b77 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -126,6 +126,8 @@ char* pa_find_config_file(const char *global, const char *local, const char *env
char *pa_get_runtime_dir(void);
char *pa_get_state_dir(void);
+char *pa_get_home_dir_malloc(void);
+char *pa_get_binary_name_malloc(void);
char *pa_runtime_path(const char *fn);
char *pa_state_path(const char *fn, pa_bool_t prepend_machine_id);
diff --git a/src/pulsecore/proplist-util.c b/src/pulsecore/proplist-util.c
index d9769bc..23864bc 100644
--- a/src/pulsecore/proplist-util.c
+++ b/src/pulsecore/proplist-util.c
@@ -186,10 +186,12 @@ void pa_init_proplist(pa_proplist *p) {
}
if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY)) {
- char t[PATH_MAX];
- if (pa_get_binary_name(t, sizeof(t))) {
+ char *t;
+
+ if ((t = pa_get_binary_name_malloc())) {
char *c = pa_utf8_filter(t);
pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
+ pa_xfree(t);
pa_xfree(c);
}
}
diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c
index a34e38f..e49f2ef 100644
--- a/src/tests/get-binary-name-test.c
+++ b/src/tests/get-binary-name-test.c
@@ -23,12 +23,33 @@
#include <limits.h>
#include <stdio.h>
+#include <string.h>
#include <pulse/util.h>
+#include <pulse/xmalloc.h>
int main(int argc, char *argv[]) {
- char exename[PATH_MAX];
+ char *exename;
+ size_t allocated = 128;
+
+ for (;;) {
+ exename = pa_xmalloc(allocated);
+
+ if (!pa_get_binary_name(exename, allocated)) {
+ printf("failed to read binary name\n");
+ pa_xfree(exename);
+ break;
+ }
+
+ if (strlen(exename) < allocated - 1) {
+ printf("%s\n", exename);
+ pa_xfree(exename);
+ break;
+ }
+
+ pa_xfree(exename);
+ allocated *= 2;
+ }
- printf("%s\n", pa_get_binary_name(exename, sizeof(exename)));
return 0;
}
diff --git a/src/utils/padsp.c b/src/utils/padsp.c
index dfa5aac..882522c 100644
--- a/src/utils/padsp.c
+++ b/src/utils/padsp.c
@@ -53,6 +53,7 @@
#include <pulse/pulseaudio.h>
#include <pulse/gccmacro.h>
#include <pulsecore/llist.h>
+#include <pulsecore/core-util.h>
/* On some systems SIOCINQ isn't defined, but FIONREAD is just an alias */
#if !defined(SIOCINQ) && defined(FIONREAD)
@@ -459,15 +460,16 @@ static void reset_params(fd_info *i) {
}
static const char *client_name(char *buf, size_t n) {
- char p[PATH_MAX];
+ char *p;
const char *e;
if ((e = getenv("PADSP_CLIENT_NAME")))
return e;
- if (pa_get_binary_name(p, sizeof(p)))
+ if ((p = pa_get_binary_name_malloc())) {
snprintf(buf, n, "OSS Emulation[%s]", p);
- else
+ pa_xfree(p);
+ } else
snprintf(buf, n, "OSS");
return buf;
commit 277822053c2f070940e5a996b9a6d95645d74590
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Aug 1 03:10:19 2009 +0200
autospawn: if creating the lock file fails, pass error code cleanly back to main process
This makes sure PA clients don't hang if $HOME is for some reason
unsuitable for autospawn lockfiles.
Closes #539
diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c
index 4436974..c0df793 100644
--- a/src/pulsecore/lock-autospawn.c
+++ b/src/pulsecore/lock-autospawn.c
@@ -55,10 +55,16 @@ static pa_mutex *mutex;
static unsigned n_ref = 0;
static int lock_fd = -1;
static pa_mutex *lock_fd_mutex = NULL;
-static pa_bool_t taken = FALSE;
-static pa_thread *thread;
+static pa_thread *thread = NULL;
static int pipe_fd[2] = { -1, -1 };
+static enum {
+ STATE_IDLE,
+ STATE_OWNING,
+ STATE_TAKEN,
+ STATE_FAILED
+} state = STATE_IDLE;
+
static void destroy_mutex(void) PA_GCC_DESTRUCTOR;
static int ref(void) {
@@ -67,15 +73,16 @@ static int ref(void) {
pa_assert(pipe_fd[0] >= 0);
pa_assert(pipe_fd[1] >= 0);
+ pa_assert(lock_fd_mutex);
n_ref++;
return 0;
}
- pa_assert(lock_fd < 0);
pa_assert(!lock_fd_mutex);
- pa_assert(!taken);
+ pa_assert(state == STATE_IDLE);
+ pa_assert(lock_fd < 0);
pa_assert(!thread);
pa_assert(pipe_fd[0] < 0);
pa_assert(pipe_fd[1] < 0);
@@ -83,14 +90,14 @@ static int ref(void) {
if (pipe(pipe_fd) < 0)
return -1;
- lock_fd_mutex = pa_mutex_new(FALSE, FALSE);
-
pa_make_fd_cloexec(pipe_fd[0]);
pa_make_fd_cloexec(pipe_fd[1]);
pa_make_fd_nonblock(pipe_fd[1]);
pa_make_fd_nonblock(pipe_fd[0]);
+ lock_fd_mutex = pa_mutex_new(FALSE, FALSE);
+
n_ref = 1;
return 0;
}
@@ -107,15 +114,18 @@ static void unref(pa_bool_t after_fork) {
if (n_ref > 0)
return;
- pa_assert(!taken);
-
if (thread) {
pa_thread_free(thread);
thread = NULL;
}
pa_mutex_lock(lock_fd_mutex);
- if (lock_fd >= 0) {
+
+ pa_assert(state != STATE_TAKEN);
+
+ if (state == STATE_OWNING) {
+
+ pa_assert(lock_fd >= 0);
if (after_fork)
pa_close(lock_fd);
@@ -127,10 +137,12 @@ static void unref(pa_bool_t after_fork) {
pa_unlock_lockfile(lf, lock_fd);
pa_xfree(lf);
-
- lock_fd = -1;
}
}
+
+ lock_fd = -1;
+ state = STATE_IDLE;
+
pa_mutex_unlock(lock_fd_mutex);
pa_mutex_free(lock_fd_mutex);
@@ -205,15 +217,24 @@ static void thread_func(void *u) {
if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
pa_log_warn(_("Cannot access autospawn lock."));
- goto finish;
+ goto fail;
}
if ((fd = pa_lock_lockfile(lf)) < 0)
- goto finish;
+ goto fail;
pa_mutex_lock(lock_fd_mutex);
- pa_assert(lock_fd < 0);
+ pa_assert(state == STATE_IDLE);
lock_fd = fd;
+ state = STATE_OWNING;
+ pa_mutex_unlock(lock_fd_mutex);
+
+ goto finish;
+
+fail:
+ pa_mutex_lock(lock_fd_mutex);
+ pa_assert(state == STATE_IDLE);
+ state = STATE_FAILED;
pa_mutex_unlock(lock_fd_mutex);
finish:
@@ -238,12 +259,10 @@ static void create_mutex(void) {
}
static void destroy_mutex(void) {
-
if (mutex)
pa_mutex_free(mutex);
}
-
int pa_autospawn_lock_init(void) {
int ret = -1;
@@ -273,13 +292,18 @@ int pa_autospawn_lock_acquire(pa_bool_t block) {
empty_pipe();
- if (lock_fd >= 0 && !taken) {
- taken = TRUE;
+ if (state == STATE_OWNING) {
+ state = STATE_TAKEN;
ret = 1;
break;
}
- if (lock_fd < 0)
+ if (state == STATE_FAILED) {
+ ret = -1;
+ break;
+ }
+
+ if (state == STATE_IDLE)
if (start_thread() < 0)
break;
@@ -310,8 +334,8 @@ void pa_autospawn_lock_release(void) {
pa_mutex_lock(mutex);
pa_assert(n_ref >= 1);
- pa_assert(taken);
- taken = FALSE;
+ pa_assert(state == STATE_TAKEN);
+ state = STATE_OWNING;
ping();
--
hooks/post-receive
PulseAudio Sound Server
More information about the pulseaudio-commits
mailing list