Improve TMPDIR handling

Patch from 'jnelson',

http://pulseaudio.org/ticket/653
This commit is contained in:
Lennart Poettering 2009-09-17 20:58:36 +02:00
parent 3de5c49e42
commit 2d9168ceb3
2 changed files with 15 additions and 2 deletions

View file

@ -1390,7 +1390,7 @@ static char* make_random_dir(mode_t m) {
if (!tmpdir || !pa_is_path_absolute(tmpdir)) if (!tmpdir || !pa_is_path_absolute(tmpdir))
tmpdir = "/tmp"; tmpdir = "/tmp";
fn = pa_sprintf_malloc("%s/pulse-XXXXXXXXXXXX", tmpdir); fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", tmpdir);
pathlen = strlen(fn); pathlen = strlen(fn);
for (;;) { for (;;) {

View file

@ -1394,10 +1394,21 @@ static int sndstat_open(int flags, int *_errno) {
"Mixers:\n" "Mixers:\n"
"0: PulseAudio Virtual OSS\n"; "0: PulseAudio Virtual OSS\n";
char fn[] = "/tmp/padsp-sndstat-XXXXXX"; char *fn;
mode_t u; mode_t u;
int fd = -1; int fd = -1;
int e; 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"); debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n");
@ -1423,6 +1434,7 @@ static int sndstat_open(int flags, int *_errno) {
} }
unlink(fn); unlink(fn);
pa_xfree(fn);
if (write(fd, sndstat, sizeof(sndstat) -1) != sizeof(sndstat)-1) { if (write(fd, sndstat, sizeof(sndstat) -1) != sizeof(sndstat)-1) {
*_errno = errno; *_errno = errno;
@ -1439,6 +1451,7 @@ static int sndstat_open(int flags, int *_errno) {
return fd; return fd;
fail: fail:
pa_xfree(fn);
if (fd >= 0) if (fd >= 0)
close(fd); close(fd);
return -1; return -1;