From 2d9168ceb388cbb6dba49cc3a531921f78ec3295 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Sep 2009 20:58:36 +0200 Subject: Improve TMPDIR handling Patch from 'jnelson', http://pulseaudio.org/ticket/653 --- src/utils/padsp.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/utils/padsp.c') diff --git a/src/utils/padsp.c b/src/utils/padsp.c index 41bfd741..c8c0874d 100644 --- a/src/utils/padsp.c +++ b/src/utils/padsp.c @@ -1394,10 +1394,21 @@ static int sndstat_open(int flags, int *_errno) { "Mixers:\n" "0: PulseAudio Virtual OSS\n"; - char fn[] = "/tmp/padsp-sndstat-XXXXXX"; + char *fn; mode_t u; int fd = -1; int e; + const char *tmpdir; + + if (!(tmpdir = getenv("TMPDIR"))) + if (!(tmpdir = getenv("TMP"))) + if (!(tmpdir = getenv("TEMP"))) + tmpdir = getenv("TEMPDIR"); + + if (!tmpdir || !pa_is_path_absolute(tmpdir)) + tmpdir = "/tmp"; + + fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", tmpdir); debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n"); @@ -1423,6 +1434,7 @@ static int sndstat_open(int flags, int *_errno) { } unlink(fn); + pa_xfree(fn); if (write(fd, sndstat, sizeof(sndstat) -1) != sizeof(sndstat)-1) { *_errno = errno; @@ -1439,6 +1451,7 @@ static int sndstat_open(int flags, int *_errno) { return fd; fail: + pa_xfree(fn); if (fd >= 0) close(fd); return -1; -- cgit From 7b76ea378460bf3e037dff90742f88f74ee70b11 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Sep 2009 21:06:54 +0200 Subject: core-util: unify how we determine the temporary directory --- src/utils/padsp.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/utils/padsp.c') diff --git a/src/utils/padsp.c b/src/utils/padsp.c index c8c0874d..2ed0a039 100644 --- a/src/utils/padsp.c +++ b/src/utils/padsp.c @@ -1398,17 +1398,8 @@ static int sndstat_open(int flags, int *_errno) { mode_t u; int fd = -1; int e; - const char *tmpdir; - if (!(tmpdir = getenv("TMPDIR"))) - if (!(tmpdir = getenv("TMP"))) - if (!(tmpdir = getenv("TEMP"))) - tmpdir = getenv("TEMPDIR"); - - if (!tmpdir || !pa_is_path_absolute(tmpdir)) - tmpdir = "/tmp"; - - fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", tmpdir); + fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", pa_get_temp_dir()); debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n"); -- cgit