mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-10 13:29:58 -05:00
use O_NOFOLLOW when creating lock files, too
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1892 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
2860685269
commit
fc00eaf1d4
1 changed files with 41 additions and 38 deletions
|
|
@ -144,7 +144,7 @@ void pa_make_fd_nonblock(int fd) {
|
||||||
|
|
||||||
if (!(v & O_NONBLOCK))
|
if (!(v & O_NONBLOCK))
|
||||||
pa_assert_se(fcntl(fd, F_SETFL, v|O_NONBLOCK) >= 0);
|
pa_assert_se(fcntl(fd, F_SETFL, v|O_NONBLOCK) >= 0);
|
||||||
|
|
||||||
#elif defined(OS_IS_WIN32)
|
#elif defined(OS_IS_WIN32)
|
||||||
u_long arg = 1;
|
u_long arg = 1;
|
||||||
if (ioctlsocket(fd, FIONBIO, &arg) < 0) {
|
if (ioctlsocket(fd, FIONBIO, &arg) < 0) {
|
||||||
|
|
@ -521,21 +521,21 @@ void pa_make_realtime(void) {
|
||||||
|
|
||||||
memset(&sp, 0, sizeof(sp));
|
memset(&sp, 0, sizeof(sp));
|
||||||
policy = 0;
|
policy = 0;
|
||||||
|
|
||||||
if ((r = pthread_getschedparam(pthread_self(), &policy, &sp)) != 0) {
|
if ((r = pthread_getschedparam(pthread_self(), &policy, &sp)) != 0) {
|
||||||
pa_log("pthread_getschedgetparam(): %s", pa_cstrerror(r));
|
pa_log("pthread_getschedgetparam(): %s", pa_cstrerror(r));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp.sched_priority = 1;
|
sp.sched_priority = 1;
|
||||||
if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) != 0) {
|
if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) != 0) {
|
||||||
pa_log_warn("pthread_setschedparam(): %s", pa_cstrerror(r));
|
pa_log_warn("pthread_setschedparam(): %s", pa_cstrerror(r));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread.");
|
pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NICE_LEVEL (-11)
|
#define NICE_LEVEL (-11)
|
||||||
|
|
@ -629,16 +629,16 @@ const char *pa_sig2str(int sig) {
|
||||||
|
|
||||||
if (sig <= 0)
|
if (sig <= 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
#ifdef NSIG
|
#ifdef NSIG
|
||||||
if (sig >= NSIG)
|
if (sig >= NSIG)
|
||||||
goto fail;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SIG2STR
|
#ifdef HAVE_SIG2STR
|
||||||
{
|
{
|
||||||
char buf[SIG2STR_MAX];
|
char buf[SIG2STR_MAX];
|
||||||
|
|
||||||
if (str2sig(sig, buf) == 0) {
|
if (str2sig(sig, buf) == 0) {
|
||||||
pa_xfree(PA_STATIC_TLS_GET(signame));
|
pa_xfree(PA_STATIC_TLS_GET(signame));
|
||||||
t = pa_sprintf_malloc("SIG%s", buf);
|
t = pa_sprintf_malloc("SIG%s", buf);
|
||||||
|
|
@ -703,8 +703,8 @@ const char *pa_sig2str(int sig) {
|
||||||
PA_STATIC_TLS_SET(signame, t);
|
PA_STATIC_TLS_SET(signame, t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
@ -943,7 +943,11 @@ int pa_lock_lockfile(const char *fn) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if ((fd = open(fn, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR)) < 0) {
|
if ((fd = open(fn, O_CREAT|O_RDWR|O_NOCTTY
|
||||||
|
#ifdef O_NOFOLLOW
|
||||||
|
|O_NOFOLLOW
|
||||||
|
#endif
|
||||||
|
, S_IRUSR|S_IWUSR)) < 0) {
|
||||||
pa_log_warn("Failed to create lock file '%s': %s", fn, pa_cstrerror(errno));
|
pa_log_warn("Failed to create lock file '%s': %s", fn, pa_cstrerror(errno));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -1131,7 +1135,7 @@ static int hexc(char c) {
|
||||||
/* Parse a hexadecimal string as created by pa_hexstr() to a BLOB */
|
/* Parse a hexadecimal string as created by pa_hexstr() to a BLOB */
|
||||||
size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) {
|
size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) {
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
|
|
||||||
pa_assert(p);
|
pa_assert(p);
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
|
|
@ -1226,7 +1230,7 @@ char *pa_runtime_path(const char *fn, char *s, size_t l) {
|
||||||
int pa_atoi(const char *s, int32_t *ret_i) {
|
int pa_atoi(const char *s, int32_t *ret_i) {
|
||||||
char *x = NULL;
|
char *x = NULL;
|
||||||
long l;
|
long l;
|
||||||
|
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
pa_assert(ret_i);
|
pa_assert(ret_i);
|
||||||
|
|
||||||
|
|
@ -1238,7 +1242,7 @@ int pa_atoi(const char *s, int32_t *ret_i) {
|
||||||
|
|
||||||
if ((int32_t) l != l)
|
if ((int32_t) l != l)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*ret_i = (int32_t) l;
|
*ret_i = (int32_t) l;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1248,7 +1252,7 @@ int pa_atoi(const char *s, int32_t *ret_i) {
|
||||||
int pa_atou(const char *s, uint32_t *ret_u) {
|
int pa_atou(const char *s, uint32_t *ret_u) {
|
||||||
char *x = NULL;
|
char *x = NULL;
|
||||||
unsigned long l;
|
unsigned long l;
|
||||||
|
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
pa_assert(ret_u);
|
pa_assert(ret_u);
|
||||||
|
|
||||||
|
|
@ -1278,21 +1282,21 @@ int pa_atof(const char *s, float *ret_f) {
|
||||||
char *x = NULL;
|
char *x = NULL;
|
||||||
float f;
|
float f;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
pa_assert(ret_f);
|
pa_assert(ret_f);
|
||||||
|
|
||||||
/* This should be locale independent */
|
/* This should be locale independent */
|
||||||
|
|
||||||
#ifdef HAVE_STRTOF_L
|
#ifdef HAVE_STRTOF_L
|
||||||
|
|
||||||
PA_ONCE_BEGIN {
|
PA_ONCE_BEGIN {
|
||||||
|
|
||||||
if ((c_locale = newlocale(LC_ALL_MASK, "C", NULL)))
|
if ((c_locale = newlocale(LC_ALL_MASK, "C", NULL)))
|
||||||
atexit(c_locale_destroy);
|
atexit(c_locale_destroy);
|
||||||
|
|
||||||
} PA_ONCE_END;
|
} PA_ONCE_END;
|
||||||
|
|
||||||
if (c_locale) {
|
if (c_locale) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
f = strtof_l(s, &x, c_locale);
|
f = strtof_l(s, &x, c_locale);
|
||||||
|
|
@ -1311,7 +1315,7 @@ int pa_atof(const char *s, float *ret_f) {
|
||||||
r = -1;
|
r = -1;
|
||||||
else
|
else
|
||||||
*ret_f = f;
|
*ret_f = f;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1323,7 +1327,7 @@ int pa_snprintf(char *str, size_t size, const char *format, ...) {
|
||||||
pa_assert(str);
|
pa_assert(str);
|
||||||
pa_assert(size > 0);
|
pa_assert(size > 0);
|
||||||
pa_assert(format);
|
pa_assert(format);
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
ret = vsnprintf(str, size, format, ap);
|
ret = vsnprintf(str, size, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
@ -1346,13 +1350,13 @@ char *pa_truncate_utf8(char *c, size_t l) {
|
||||||
|
|
||||||
while (l > 0 && !pa_utf8_valid(c))
|
while (l > 0 && !pa_utf8_valid(c))
|
||||||
c[--l] = 0;
|
c[--l] = 0;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pa_getcwd(void) {
|
char *pa_getcwd(void) {
|
||||||
size_t l = 128;
|
size_t l = 128;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char *p = pa_xnew(char, l);
|
char *p = pa_xnew(char, l);
|
||||||
if (getcwd(p, l))
|
if (getcwd(p, l))
|
||||||
|
|
@ -1369,7 +1373,7 @@ char *pa_getcwd(void) {
|
||||||
char *pa_make_path_absolute(const char *p) {
|
char *pa_make_path_absolute(const char *p) {
|
||||||
char *r;
|
char *r;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
||||||
pa_assert(p);
|
pa_assert(p);
|
||||||
|
|
||||||
if (p[0] == '/')
|
if (p[0] == '/')
|
||||||
|
|
@ -1391,47 +1395,47 @@ void *pa_will_need(const void *p, size_t l) {
|
||||||
size_t size;
|
size_t size;
|
||||||
int r;
|
int r;
|
||||||
size_t bs;
|
size_t bs;
|
||||||
|
|
||||||
pa_assert(p);
|
pa_assert(p);
|
||||||
pa_assert(l > 0);
|
pa_assert(l > 0);
|
||||||
|
|
||||||
a = PA_PAGE_ALIGN_PTR(p);
|
a = PA_PAGE_ALIGN_PTR(p);
|
||||||
size = (const uint8_t*) p + l - (const uint8_t*) a;
|
size = (const uint8_t*) p + l - (const uint8_t*) a;
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_MADVISE
|
#ifdef HAVE_POSIX_MADVISE
|
||||||
if ((r = posix_madvise((void*) a, size, POSIX_MADV_WILLNEED)) == 0) {
|
if ((r = posix_madvise((void*) a, size, POSIX_MADV_WILLNEED)) == 0) {
|
||||||
pa_log_debug("posix_madvise() worked fine!");
|
pa_log_debug("posix_madvise() worked fine!");
|
||||||
return (void*) p;
|
return (void*) p;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Most likely the memory was not mmap()ed from a file and thus
|
/* Most likely the memory was not mmap()ed from a file and thus
|
||||||
* madvise() didn't work, so let's misuse mlock() do page this
|
* madvise() didn't work, so let's misuse mlock() do page this
|
||||||
* stuff back into RAM. Yeah, let's fuck with the MM! It's so
|
* stuff back into RAM. Yeah, let's fuck with the MM! It's so
|
||||||
* inviting, the man page of mlock() tells us: "All pages that
|
* inviting, the man page of mlock() tells us: "All pages that
|
||||||
* contain a part of the specified address range are guaranteed to
|
* contain a part of the specified address range are guaranteed to
|
||||||
* be resident in RAM when the call returns successfully." */
|
* be resident in RAM when the call returns successfully." */
|
||||||
|
|
||||||
#ifdef RLIMIT_MEMLOCK
|
#ifdef RLIMIT_MEMLOCK
|
||||||
pa_assert_se(getrlimit(RLIMIT_MEMLOCK, &rlim) == 0);
|
pa_assert_se(getrlimit(RLIMIT_MEMLOCK, &rlim) == 0);
|
||||||
|
|
||||||
if (rlim.rlim_cur < PA_PAGE_SIZE) {
|
if (rlim.rlim_cur < PA_PAGE_SIZE) {
|
||||||
pa_log_debug("posix_madvise() failed (or doesn't exist), resource limits don't allow mlock(), can't page in data: %s", pa_cstrerror(r));
|
pa_log_debug("posix_madvise() failed (or doesn't exist), resource limits don't allow mlock(), can't page in data: %s", pa_cstrerror(r));
|
||||||
return (void*) p;
|
return (void*) p;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs = PA_PAGE_ALIGN(rlim.rlim_cur);
|
bs = PA_PAGE_ALIGN(rlim.rlim_cur);
|
||||||
#else
|
#else
|
||||||
bs = PA_PAGE_SIZE*4;
|
bs = PA_PAGE_SIZE*4;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pa_log_debug("posix_madvise() failed (or doesn't exist), trying mlock(): %s", pa_cstrerror(r));
|
pa_log_debug("posix_madvise() failed (or doesn't exist), trying mlock(): %s", pa_cstrerror(r));
|
||||||
|
|
||||||
while (size > 0 && bs > 0) {
|
while (size > 0 && bs > 0) {
|
||||||
|
|
||||||
if (bs > size)
|
if (bs > size)
|
||||||
bs = size;
|
bs = size;
|
||||||
|
|
||||||
if (mlock(a, bs) < 0) {
|
if (mlock(a, bs) < 0) {
|
||||||
bs = PA_PAGE_ALIGN(bs / 2);
|
bs = PA_PAGE_ALIGN(bs / 2);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1453,13 +1457,12 @@ void *pa_will_need(const void *p, size_t l) {
|
||||||
|
|
||||||
void pa_close_pipe(int fds[2]) {
|
void pa_close_pipe(int fds[2]) {
|
||||||
pa_assert(fds);
|
pa_assert(fds);
|
||||||
|
|
||||||
if (fds[0] >= 0)
|
if (fds[0] >= 0)
|
||||||
pa_assert_se(pa_close(fds[0]) == 0);
|
pa_assert_se(pa_close(fds[0]) == 0);
|
||||||
|
|
||||||
if (fds[1] >= 0)
|
if (fds[1] >= 0)
|
||||||
pa_assert_se(pa_close(fds[1]) == 0);
|
pa_assert_se(pa_close(fds[1]) == 0);
|
||||||
|
|
||||||
fds[0] = fds[1] = -1;
|
fds[0] = fds[1] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue