mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-10 13:29:58 -05:00
use cloexec wrappers wherever applicable
This commit is contained in:
parent
9c1a98953f
commit
65e7bc18a9
25 changed files with 39 additions and 91 deletions
|
|
@ -70,10 +70,6 @@ static int generate(int fd, void *ret_data, size_t length) {
|
|||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOCTTY
|
||||
#define O_NOCTTY 0
|
||||
#endif
|
||||
|
||||
/* Load an euthorization cookie from file fn and store it in data. If
|
||||
* the cookie file doesn't exist, create it */
|
||||
static int load(const char *fn, void *data, size_t length) {
|
||||
|
|
@ -86,9 +82,9 @@ static int load(const char *fn, void *data, size_t length) {
|
|||
pa_assert(data);
|
||||
pa_assert(length > 0);
|
||||
|
||||
if ((fd = open(fn, O_RDWR|O_CREAT|O_BINARY|O_NOCTTY, S_IRUSR|S_IWUSR)) < 0) {
|
||||
if ((fd = pa_open_cloexec(fn, O_RDWR|O_CREAT|O_BINARY, S_IRUSR|S_IWUSR)) < 0) {
|
||||
|
||||
if (errno != EACCES || (fd = open(fn, O_RDONLY|O_BINARY|O_NOCTTY)) < 0) {
|
||||
if (errno != EACCES || (fd = open(fn, O_RDONLY|O_BINARY)) < 0) {
|
||||
pa_log_warn("Failed to open cookie file '%s': %s", fn, pa_cstrerror(errno));
|
||||
goto finish;
|
||||
} else
|
||||
|
|
@ -204,7 +200,7 @@ int pa_authkey_save(const char *fn, const void *data, size_t length) {
|
|||
if (!(p = normalize_path(fn)))
|
||||
return -2;
|
||||
|
||||
if ((fd = open(p, O_RDWR|O_CREAT|O_NOCTTY, S_IRUSR|S_IWUSR)) < 0) {
|
||||
if ((fd = pa_open_cloexec(p, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR)) < 0) {
|
||||
pa_log_warn("Failed to open cookie file '%s': %s", fn, pa_cstrerror(errno));
|
||||
goto finish;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1200,10 +1200,7 @@ int pa_lock_lockfile(const char *fn) {
|
|||
for (;;) {
|
||||
struct stat st;
|
||||
|
||||
if ((fd = open(fn, O_CREAT|O_RDWR
|
||||
#ifdef O_NOCTTY
|
||||
|O_NOCTTY
|
||||
#endif
|
||||
if ((fd = pa_open_cloexec(fn, O_CREAT|O_RDWR
|
||||
#ifdef O_NOFOLLOW
|
||||
|O_NOFOLLOW
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ static char *get_cpuinfo(void) {
|
|||
|
||||
cpuinfo = pa_xmalloc(MAX_BUFFER);
|
||||
|
||||
if ((fd = open("/proc/cpuinfo", O_RDONLY)) < 0) {
|
||||
if ((fd = pa_open_cloexec("/proc/cpuinfo", O_RDONLY, 0)) < 0) {
|
||||
pa_xfree(cpuinfo);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,19 +62,15 @@ pa_fdsem *pa_fdsem_new(void) {
|
|||
f = pa_xmalloc(PA_ALIGN(sizeof(pa_fdsem)) + PA_ALIGN(sizeof(pa_fdsem_data)));
|
||||
|
||||
#ifdef HAVE_SYS_EVENTFD_H
|
||||
if ((f->efd = eventfd(0, 0)) >= 0) {
|
||||
pa_make_fd_cloexec(f->efd);
|
||||
if ((f->efd = eventfd(0, EFD_CLOEXEC)) >= 0)
|
||||
f->fds[0] = f->fds[1] = -1;
|
||||
} else
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (pipe(f->fds) < 0) {
|
||||
if (pa_pipe_cloexec(f->fds) < 0) {
|
||||
pa_xfree(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(f->fds[0]);
|
||||
pa_make_fd_cloexec(f->fds[1]);
|
||||
}
|
||||
|
||||
f->data = (pa_fdsem_data*) ((uint8_t*) f + PA_ALIGN(sizeof(pa_fdsem)));
|
||||
|
|
@ -114,12 +110,11 @@ pa_fdsem *pa_fdsem_new_shm(pa_fdsem_data *data, int* event_fd) {
|
|||
|
||||
f = pa_xnew(pa_fdsem, 1);
|
||||
|
||||
if ((f->efd = eventfd(0, 0)) < 0) {
|
||||
if ((f->efd = eventfd(0, EFD_CLOEXEC)) < 0) {
|
||||
pa_xfree(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(f->efd);
|
||||
f->fds[0] = f->fds[1] = -1;
|
||||
f->data = data;
|
||||
|
||||
|
|
|
|||
|
|
@ -87,12 +87,9 @@ static int ref(void) {
|
|||
pa_assert(pipe_fd[0] < 0);
|
||||
pa_assert(pipe_fd[1] < 0);
|
||||
|
||||
if (pipe(pipe_fd) < 0)
|
||||
if (pa_pipe_cloexec(pipe_fd) < 0)
|
||||
return -1;
|
||||
|
||||
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]);
|
||||
|
||||
|
|
|
|||
|
|
@ -88,10 +88,7 @@ static int open_pid_file(const char *fn, int mode) {
|
|||
for (;;) {
|
||||
struct stat st;
|
||||
|
||||
if ((fd = open(fn, mode
|
||||
#ifdef O_NOCTTY
|
||||
|O_NOCTTY
|
||||
#endif
|
||||
if ((fd = pa_open_cloexec(fn, mode
|
||||
#ifdef O_NOFOLLOW
|
||||
|O_NOFOLLOW
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -62,11 +62,7 @@ static int random_proper(void *ret_data, size_t length) {
|
|||
while (*device) {
|
||||
ret = 0;
|
||||
|
||||
if ((fd = open(*device, O_RDONLY
|
||||
#ifdef O_NOCTTY
|
||||
| O_NOCTTY
|
||||
#endif
|
||||
)) >= 0) {
|
||||
if ((fd = pa_open_cloexec(*device, O_RDONLY, 0)) >= 0) {
|
||||
|
||||
if ((r = pa_loop_read(fd, ret_data, length, NULL)) < 0 || (size_t) r != length)
|
||||
ret = -1;
|
||||
|
|
|
|||
|
|
@ -1342,7 +1342,7 @@ static void propagate_reference_volume(pa_sink *s) {
|
|||
void pa_sink_set_volume(
|
||||
pa_sink *s,
|
||||
const pa_cvolume *volume,
|
||||
pa_bool_t sendmsg,
|
||||
pa_bool_t send_msg,
|
||||
pa_bool_t save) {
|
||||
|
||||
pa_cvolume old_reference_volume;
|
||||
|
|
@ -1411,7 +1411,7 @@ void pa_sink_set_volume(
|
|||
s->soft_volume = s->real_volume;
|
||||
|
||||
/* This tells the sink that soft and/or virtual volume changed */
|
||||
if (sendmsg)
|
||||
if (send_msg)
|
||||
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_VOLUME, NULL, 0, NULL) == 0);
|
||||
|
||||
if (reference_changed)
|
||||
|
|
|
|||
|
|
@ -257,13 +257,11 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size
|
|||
|
||||
c->local = pa_socket_address_is_local(sa);
|
||||
|
||||
if ((c->fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
|
||||
if ((c->fd = pa_socket_cloexec(sa->sa_family, SOCK_STREAM, 0)) < 0) {
|
||||
pa_log("socket(): %s", pa_cstrerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(c->fd);
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -104,13 +104,11 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, pa_io_ev
|
|||
|
||||
pa_socket_server_ref(s);
|
||||
|
||||
if ((nfd = accept(fd, NULL, NULL)) < 0) {
|
||||
if ((nfd = pa_accept_cloexec(fd, NULL, NULL)) < 0) {
|
||||
pa_log("accept(): %s", pa_cstrerror(errno));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(nfd);
|
||||
|
||||
if (!s->on_connection) {
|
||||
pa_close(nfd);
|
||||
goto finish;
|
||||
|
|
@ -186,13 +184,11 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
|
|||
pa_assert(m);
|
||||
pa_assert(filename);
|
||||
|
||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
pa_log("socket(): %s", pa_cstrerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(fd);
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sun_family = AF_UNIX;
|
||||
pa_strlcpy(sa.sun_path, filename, sizeof(sa.sun_path));
|
||||
|
|
@ -246,13 +242,11 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
|
|||
pa_assert(m);
|
||||
pa_assert(port);
|
||||
|
||||
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
if ((fd = pa_socket_cloexec(PF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
pa_log("socket(PF_INET): %s", pa_cstrerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(fd);
|
||||
|
||||
#ifdef SO_REUSEADDR
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
|
||||
pa_log("setsockopt(): %s", pa_cstrerror(errno));
|
||||
|
|
@ -299,13 +293,11 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
|
|||
pa_assert(m);
|
||||
pa_assert(port > 0);
|
||||
|
||||
if ((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
if ((fd = pa_socket_cloexec(PF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
pa_log("socket(PF_INET6): %s", pa_cstrerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_make_fd_cloexec(fd);
|
||||
|
||||
#ifdef IPV6_V6ONLY
|
||||
on = 1;
|
||||
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ int pa_unix_socket_is_stale(const char *fn) {
|
|||
|
||||
pa_assert(fn);
|
||||
|
||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
pa_log("socket(): %s", pa_cstrerror(errno));
|
||||
goto finish;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,11 +252,7 @@ int pa_play_file(
|
|||
u->readf_function = NULL;
|
||||
u->memblockq = NULL;
|
||||
|
||||
if ((fd = open(fname, O_RDONLY
|
||||
#ifdef O_NOCTTY
|
||||
|O_NOCTTY
|
||||
#endif
|
||||
)) < 0) {
|
||||
if ((fd = pa_open_cloexec(fname, O_RDONLY, 0)) < 0) {
|
||||
pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,11 +62,7 @@ int pa_sound_file_load(
|
|||
|
||||
pa_memchunk_reset(chunk);
|
||||
|
||||
if ((fd = open(fname, O_RDONLY
|
||||
#ifdef O_NOCTTY
|
||||
|O_NOCTTY
|
||||
#endif
|
||||
)) < 0) {
|
||||
if ((fd = pa_open_cloexec(fname, O_RDONLY, 0)) < 0) {
|
||||
pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno));
|
||||
goto finish;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue