[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.19-206-ga82c6b0

Lennart Poettering gitmailer-noreply at 0pointer.de
Thu Oct 29 20:55:27 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  754644fa6e1ec83dba85bf586a2b09c2283aa096 (commit)

- Log -----------------------------------------------------------------
a82c6b0 socket-util: drop redundant casts
75f7a97 socket-util: allocate at least sizeof(sockaddr_storage) space
168be38 use pa_fopen_cloexec() where applicable
88b7295 tdb: use O_CLOEXEC if available
752727a core-util: introduce pa_fopen_cloexec()
a698ee3 core-util: make sure to enable FD_CLOEXEC unconditionally to cope with kernels that silently accept but ignore O_CLOEXEC
65e7bc1 use cloexec wrappers wherever applicable
9c1a989 core-util: introduce FD_CLOEXEC wrappers for open/socket/pipe/accept
-----------------------------------------------------------------------

Summary of changes:
 configure.ac                                |    2 +-
 src/daemon/cpulimit.c                       |    4 +-
 src/daemon/daemon-conf.c                    |    4 +-
 src/modules/module-cli.c                    |    2 +-
 src/modules/module-default-device-restore.c |    8 +-
 src/modules/module-detect.c                 |    8 +-
 src/modules/module-match.c                  |    2 +-
 src/modules/module-mmkbd-evdev.c            |    2 +-
 src/modules/module-pipe-sink.c              |    3 +-
 src/modules/module-pipe-source.c            |    3 +-
 src/modules/module-solaris.c                |    2 +-
 src/modules/module-udev-detect.c            |    2 +-
 src/modules/oss/oss-util.c                  |   18 ++--
 src/modules/rtp/module-rtp-recv.c           |    2 +-
 src/modules/rtp/module-rtp-send.c           |    6 +-
 src/pulse/client-conf.c                     |    2 +-
 src/pulse/mainloop-signal.c                 |    4 +-
 src/pulse/mainloop.c                        |    4 +-
 src/pulsecore/authkey.c                     |   10 +--
 src/pulsecore/cli-command.c                 |    2 +-
 src/pulsecore/conf-parser.c                 |    2 +-
 src/pulsecore/core-util.c                   |  126 +++++++++++++++++++++++++--
 src/pulsecore/core-util.h                   |    7 ++
 src/pulsecore/cpu-arm.c                     |    2 +-
 src/pulsecore/database-simple.c             |    4 +-
 src/pulsecore/database-tdb.c                |   43 +++++++--
 src/pulsecore/fdsem.c                       |   13 +--
 src/pulsecore/lock-autospawn.c              |    5 +-
 src/pulsecore/pid.c                         |    7 +-
 src/pulsecore/random.c                      |    6 +-
 src/pulsecore/sample-util.c                 |    2 +-
 src/pulsecore/sink.c                        |    4 +-
 src/pulsecore/socket-client.c               |    4 +-
 src/pulsecore/socket-server.c               |   16 +---
 src/pulsecore/socket-util.c                 |   30 +++---
 src/pulsecore/sound-file-stream.c           |    6 +-
 src/pulsecore/sound-file.c                  |    6 +-
 src/utils/pacat.c                           |    2 +-
 src/utils/pacmd.c                           |    2 +-
 39 files changed, 235 insertions(+), 142 deletions(-)

-----------------------------------------------------------------------

commit 9c1a98953f25aff7f11af80a073c9c46dee2438c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 03:30:42 2009 +0100

    core-util: introduce FD_CLOEXEC wrappers for open/socket/pipe/accept

diff --git a/configure.ac b/configure.ac
index d7f55ac..1022a6e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -445,7 +445,7 @@ AC_CHECK_FUNCS_ONCE([lstat])
 
 # Non-standard
 
-AC_CHECK_FUNCS_ONCE([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str strtof_l])
+AC_CHECK_FUNCS_ONCE([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str strtof_l pipe2 accept4])
 
 AC_FUNC_ALLOCA
 
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 27e09cb..34516ee 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2889,3 +2889,82 @@ const char *pa_get_temp_dir(void) {
 
     return "/tmp";
 }
+
+int pa_open_cloexec(const char *fn, int flags, mode_t mode) {
+    int fd;
+
+#ifdef O_NOCTTY
+    flags |= O_NOCTTY;
+#endif
+
+#ifdef O_CLOEXEC
+    if ((fd = open(fn, flags|O_CLOEXEC, mode)) >= 0)
+        return fd;
+
+    if (errno != EINVAL)
+        return fd;
+#endif
+
+    if ((fd = open(fn, flags, mode)) < 0)
+        return fd;
+
+    pa_make_fd_cloexec(fd);
+    return fd;
+}
+
+int pa_socket_cloexec(int domain, int type, int protocol) {
+    int fd;
+
+#ifdef SOCK_CLOEXEC
+    if ((fd = socket(domain, type | SOCK_CLOEXEC, protocol)) >= 0)
+        return fd;
+
+    if (errno != EINVAL)
+        return fd;
+#endif
+
+    if ((fd = socket(domain, type, protocol)) < 0)
+        return fd;
+
+    pa_make_fd_cloexec(fd);
+    return fd;
+}
+
+int pa_pipe_cloexec(int pipefd[2]) {
+    int r;
+
+#ifdef HAVE_PIPE2
+    if ((r = pipe2(pipefd, O_CLOEXEC)) >= 0)
+        return r;
+
+    if (errno != EINVAL && errno != ENOSYS)
+        return r;
+#endif
+
+    if ((r = pipe(pipefd)) < 0)
+        return r;
+
+    pa_make_fd_cloexec(pipefd[0]);
+    pa_make_fd_cloexec(pipefd[1]);
+
+    return 0;
+}
+
+int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
+    int fd;
+
+#ifdef HAVE_ACCEPT4
+    if ((fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC)) >= 0)
+        return fd;
+
+    if (errno != EINVAL && errno != ENOSYS)
+        return fd;
+#endif
+
+    if ((fd = accept(sockfd, addr, addrlen)) < 0)
+        return fd;
+
+    pa_make_fd_cloexec(fd);
+
+    return 0;
+}
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 9986b14..323fdcb 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -28,6 +28,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
@@ -258,4 +259,9 @@ pa_bool_t pa_run_from_build_tree(void);
 
 const char *pa_get_temp_dir(void);
 
+int pa_open_cloexec(const char *fn, int flags, mode_t mode);
+int pa_socket_cloexec(int domain, int type, int protocol);
+int pa_pipe_cloexec(int pipefd[2]);
+int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+
 #endif

commit 65e7bc18a9a7b89e55b87a74ae47d45269b51847
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 03:32:38 2009 +0100

    use cloexec wrappers wherever applicable

diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c
index c2877ec..f5042a7 100644
--- a/src/daemon/cpulimit.c
+++ b/src/daemon/cpulimit.c
@@ -188,15 +188,13 @@ int pa_cpu_limit_init(pa_mainloop_api *m) {
     last_time = pa_rtclock_now();
 
     /* Prepare the main loop pipe */
-    if (pipe(the_pipe) < 0) {
+    if (pa_pipe_cloexec(the_pipe) < 0) {
         pa_log("pipe() failed: %s", pa_cstrerror(errno));
         return -1;
     }
 
     pa_make_fd_nonblock(the_pipe[0]);
     pa_make_fd_nonblock(the_pipe[1]);
-    pa_make_fd_cloexec(the_pipe[0]);
-    pa_make_fd_cloexec(the_pipe[1]);
 
     api = m;
     io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c
index 516bf41..14a9dd3 100644
--- a/src/modules/module-mmkbd-evdev.c
+++ b/src/modules/module-mmkbd-evdev.c
@@ -175,7 +175,7 @@ int pa__init(pa_module*m) {
     u->fd = -1;
     u->fd_type = 0;
 
-    if ((u->fd = open(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY|O_NOCTTY)) < 0) {
+    if ((u->fd = pa_open_cloexec(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY, 0)) < 0) {
         pa_log("Failed to open evdev device: %s", pa_cstrerror(errno));
         goto fail;
     }
diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c
index 9c16932..10cc341 100644
--- a/src/modules/module-pipe-sink.c
+++ b/src/modules/module-pipe-sink.c
@@ -253,12 +253,11 @@ int pa__init(pa_module*m) {
     u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME));
 
     mkfifo(u->filename, 0666);
-    if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) {
+    if ((u->fd = pa_open_cloexec(u->filename, O_RDWR, 0)) < 0) {
         pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno));
         goto fail;
     }
 
-    pa_make_fd_cloexec(u->fd);
     pa_make_fd_nonblock(u->fd);
 
     if (fstat(u->fd, &st) < 0) {
diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c
index 49104f8..de68093 100644
--- a/src/modules/module-pipe-source.c
+++ b/src/modules/module-pipe-source.c
@@ -238,12 +238,11 @@ int pa__init(pa_module*m) {
     u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME));
 
     mkfifo(u->filename, 0666);
-    if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) {
+    if ((u->fd = pa_open_cloexec(u->filename, O_RDWR, 0)) < 0) {
         pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno));
         goto fail;
     }
 
-    pa_make_fd_cloexec(u->fd);
     pa_make_fd_nonblock(u->fd);
 
     if (fstat(u->fd, &st) < 0) {
diff --git a/src/modules/module-solaris.c b/src/modules/module-solaris.c
index b0d4db4..955997b 100644
--- a/src/modules/module-solaris.c
+++ b/src/modules/module-solaris.c
@@ -327,7 +327,7 @@ static int open_audio_device(struct userdata *u, pa_sample_spec *ss) {
     pa_assert(u);
     pa_assert(ss);
 
-    if ((u->fd = open(u->device_name, u->mode | O_NONBLOCK)) < 0) {
+    if ((u->fd = pa_open_cloexec(u->device_name, u->mode | O_NONBLOCK)) < 0) {
         pa_log_warn("open %s failed (%s)", u->device_name, pa_cstrerror(errno));
         return -1;
     }
diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c
index 5a109ae..41af3ba 100644
--- a/src/modules/oss/oss-util.c
+++ b/src/modules/oss/oss-util.c
@@ -55,7 +55,7 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) {
         pcaps = &caps;
 
     if (*mode == O_RDWR) {
-        if ((fd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) >= 0) {
+        if ((fd = pa_open_cloexec(device, O_RDWR|O_NDELAY, 0)) >= 0) {
             ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
 
             if (ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps) < 0) {
@@ -71,14 +71,14 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) {
             pa_close(fd);
         }
 
-        if ((fd = open(device, (*mode = O_WRONLY)|O_NDELAY|O_NOCTTY)) < 0) {
-            if ((fd = open(device, (*mode = O_RDONLY)|O_NDELAY|O_NOCTTY)) < 0) {
+        if ((fd = pa_open_cloexec(device, (*mode = O_WRONLY)|O_NDELAY, 0)) < 0) {
+            if ((fd = pa_open_cloexec(device, (*mode = O_RDONLY)|O_NDELAY, 0)) < 0) {
                 pa_log("open('%s'): %s", device, pa_cstrerror(errno));
                 goto fail;
             }
         }
     } else {
-        if ((fd = open(device, *mode|O_NDELAY|O_NOCTTY)) < 0) {
+        if ((fd = pa_open_cloexec(device, *mode|O_NDELAY, 0)) < 0) {
             pa_log("open('%s'): %s", device, pa_cstrerror(errno));
             goto fail;
         }
@@ -145,8 +145,6 @@ success:
     pa_log_debug("capabilities:%s", t);
     pa_xfree(t);
 
-    pa_make_fd_cloexec(fd);
-
     return fd;
 
 fail:
@@ -403,7 +401,7 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
 static int open_mixer(const char *mixer) {
     int fd;
 
-    if ((fd = open(mixer, O_RDWR|O_NDELAY|O_NOCTTY)) >= 0)
+    if ((fd = pa_open_cloexec(mixer, O_RDWR|O_NDELAY, 0)) >= 0)
         return fd;
 
     return -1;
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index 1a05f57..7dbb1ef 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -390,7 +390,7 @@ static int mcast_socket(const struct sockaddr* sa, socklen_t salen) {
     pa_assert(salen > 0);
 
     af = sa->sa_family;
-    if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) {
+    if ((fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) {
         pa_log("Failed to create socket: %s", pa_cstrerror(errno));
         goto fail;
     }
diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c
index 8e1cfe3..ab81522 100644
--- a/src/modules/rtp/module-rtp-send.c
+++ b/src/modules/rtp/module-rtp-send.c
@@ -262,7 +262,7 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) {
+    if ((fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) {
         pa_log("socket() failed: %s", pa_cstrerror(errno));
         goto fail;
     }
@@ -277,7 +277,7 @@ int pa__init(pa_module*m) {
 #endif
     }
 
-    if ((sap_fd = socket(af, SOCK_DGRAM, 0)) < 0) {
+    if ((sap_fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) {
         pa_log("socket() failed: %s", pa_cstrerror(errno));
         goto fail;
     }
@@ -316,8 +316,6 @@ int pa__init(pa_module*m) {
     /* If the socket queue is full, let's drop packets */
     pa_make_fd_nonblock(fd);
     pa_make_udp_socket_low_delay(fd);
-    pa_make_fd_cloexec(fd);
-    pa_make_fd_cloexec(sap_fd);
 
     pa_source_output_new_data_init(&data);
     pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, "RTP Monitor Stream");
diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c
index 3dc7439..70c0122 100644
--- a/src/pulse/mainloop-signal.c
+++ b/src/pulse/mainloop-signal.c
@@ -124,15 +124,13 @@ int pa_signal_init(pa_mainloop_api *a) {
     pa_assert(signal_pipe[1] == -1);
     pa_assert(!io_event);
 
-    if (pipe(signal_pipe) < 0) {
+    if (pa_pipe_cloexec(signal_pipe) < 0) {
         pa_log("pipe(): %s", pa_cstrerror(errno));
         return -1;
     }
 
     pa_make_fd_nonblock(signal_pipe[0]);
     pa_make_fd_nonblock(signal_pipe[1]);
-    pa_make_fd_cloexec(signal_pipe[0]);
-    pa_make_fd_cloexec(signal_pipe[1]);
 
     api = a;
 
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 090ac8c..6cd089e 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -482,7 +482,7 @@ pa_mainloop *pa_mainloop_new(void) {
 
     m = pa_xnew0(pa_mainloop, 1);
 
-    if (pipe(m->wakeup_pipe) < 0) {
+    if (pa_pipe_cloexec(m->wakeup_pipe) < 0) {
         pa_log_error("ERROR: cannot create wakeup pipe");
         pa_xfree(m);
         return NULL;
@@ -490,8 +490,6 @@ pa_mainloop *pa_mainloop_new(void) {
 
     pa_make_fd_nonblock(m->wakeup_pipe[0]);
     pa_make_fd_nonblock(m->wakeup_pipe[1]);
-    pa_make_fd_cloexec(m->wakeup_pipe[0]);
-    pa_make_fd_cloexec(m->wakeup_pipe[1]);
 
     m->rebuild_pollfds = TRUE;
 
diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index 15613e2..d671e36 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -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;
     }
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 34516ee..19e1296 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -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
diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c
index 453b784..6bb2ead 100644
--- a/src/pulsecore/cpu-arm.c
+++ b/src/pulsecore/cpu-arm.c
@@ -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;
     }
diff --git a/src/pulsecore/fdsem.c b/src/pulsecore/fdsem.c
index 380f34f..ea14e8a 100644
--- a/src/pulsecore/fdsem.c
+++ b/src/pulsecore/fdsem.c
@@ -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;
 
diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c
index c0df793..65e3563 100644
--- a/src/pulsecore/lock-autospawn.c
+++ b/src/pulsecore/lock-autospawn.c
@@ -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]);
 
diff --git a/src/pulsecore/pid.c b/src/pulsecore/pid.c
index 996946c..c92e831 100644
--- a/src/pulsecore/pid.c
+++ b/src/pulsecore/pid.c
@@ -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
diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c
index 518c281..a87d24e 100644
--- a/src/pulsecore/random.c
+++ b/src/pulsecore/random.c
@@ -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;
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index bda92fc..221b569 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -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)
diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c
index b9d6950..ef3c29e 100644
--- a/src/pulsecore/socket-client.c
+++ b/src/pulsecore/socket-client.c
@@ -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
diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c
index e660700..5d55de3 100644
--- a/src/pulsecore/socket-server.c
+++ b/src/pulsecore/socket-server.c
@@ -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)
diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 5fd5dd6..651779f 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -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;
     }
diff --git a/src/pulsecore/sound-file-stream.c b/src/pulsecore/sound-file-stream.c
index 16de492..53674ba 100644
--- a/src/pulsecore/sound-file-stream.c
+++ b/src/pulsecore/sound-file-stream.c
@@ -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;
     }
diff --git a/src/pulsecore/sound-file.c b/src/pulsecore/sound-file.c
index 2d9b76a..d8c10b1 100644
--- a/src/pulsecore/sound-file.c
+++ b/src/pulsecore/sound-file.c
@@ -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;
     }
diff --git a/src/utils/pacat.c b/src/utils/pacat.c
index 5f29ba3..d348c16 100644
--- a/src/utils/pacat.c
+++ b/src/utils/pacat.c
@@ -906,7 +906,7 @@ int main(int argc, char *argv[]) {
 
         filename = argv[optind];
 
-        if ((fd = open(argv[optind], mode == PLAYBACK ? O_RDONLY : O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) {
+        if ((fd = pa_open_cloexec(argv[optind], mode == PLAYBACK ? O_RDONLY : O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) {
             pa_log(_("open(): %s"), strerror(errno));
             goto quit;
         }
diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
index 5ef57e3..ef58e9c 100644
--- a/src/utils/pacmd.c
+++ b/src/utils/pacmd.c
@@ -70,7 +70,7 @@ int main(int argc, char*argv[]) {
         goto fail;
     }
 
-    if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
+    if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) {
         pa_log(_("socket(PF_UNIX, SOCK_STREAM, 0): %s"), strerror(errno));
         goto fail;
     }

commit a698ee3f52e9d61b378cb0dad2cfb1bcc31c708a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 04:16:59 2009 +0100

    core-util: make sure to enable FD_CLOEXEC unconditionally to cope with kernels that silently accept but ignore O_CLOEXEC

diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 19e1296..a199daa 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2896,7 +2896,7 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode) {
 
 #ifdef O_CLOEXEC
     if ((fd = open(fn, flags|O_CLOEXEC, mode)) >= 0)
-        return fd;
+        goto finish;
 
     if (errno != EINVAL)
         return fd;
@@ -2905,6 +2905,10 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode) {
     if ((fd = open(fn, flags, mode)) < 0)
         return fd;
 
+finish:
+    /* Some implementations might simply ignore O_CLOEXEC if it is not
+     * understood, make sure FD_CLOEXEC is enabled anyway */
+
     pa_make_fd_cloexec(fd);
     return fd;
 }
@@ -2914,7 +2918,7 @@ int pa_socket_cloexec(int domain, int type, int protocol) {
 
 #ifdef SOCK_CLOEXEC
     if ((fd = socket(domain, type | SOCK_CLOEXEC, protocol)) >= 0)
-        return fd;
+        goto finish;
 
     if (errno != EINVAL)
         return fd;
@@ -2923,6 +2927,10 @@ int pa_socket_cloexec(int domain, int type, int protocol) {
     if ((fd = socket(domain, type, protocol)) < 0)
         return fd;
 
+finish:
+    /* Some implementations might simply ignore SOCK_CLOEXEC if it is
+     * not understood, make sure FD_CLOEXEC is enabled anyway */
+
     pa_make_fd_cloexec(fd);
     return fd;
 }
@@ -2932,7 +2940,7 @@ int pa_pipe_cloexec(int pipefd[2]) {
 
 #ifdef HAVE_PIPE2
     if ((r = pipe2(pipefd, O_CLOEXEC)) >= 0)
-        return r;
+        goto finish;
 
     if (errno != EINVAL && errno != ENOSYS)
         return r;
@@ -2941,6 +2949,7 @@ int pa_pipe_cloexec(int pipefd[2]) {
     if ((r = pipe(pipefd)) < 0)
         return r;
 
+finish:
     pa_make_fd_cloexec(pipefd[0]);
     pa_make_fd_cloexec(pipefd[1]);
 

commit 752727a13d2d55439aefe618677f7e932acc9862
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 04:20:24 2009 +0100

    core-util: introduce pa_fopen_cloexec()

diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index a199daa..40da8f4 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2961,7 +2961,7 @@ int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
 
 #ifdef HAVE_ACCEPT4
     if ((fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC)) >= 0)
-        return fd;
+        goto finish;
 
     if (errno != EINVAL && errno != ENOSYS)
         return fd;
@@ -2970,7 +2970,32 @@ int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
     if ((fd = accept(sockfd, addr, addrlen)) < 0)
         return fd;
 
+finish:
     pa_make_fd_cloexec(fd);
+    return fd;
+}
 
-    return 0;
+FILE* pa_fopen_cloexec(const char *path, const char *mode) {
+    FILE *f;
+    char *m;
+
+    m = pa_sprintf_malloc("%se", mode);
+
+    errno = 0;
+    if ((f = fopen(path, m))) {
+        pa_xfree(m);
+        goto finish;
+    }
+
+    pa_xfree(m);
+
+    if (errno != EINVAL)
+        return NULL;
+
+    if (!(f = fopen(path, mode)))
+        return NULL;
+
+finish:
+    pa_make_fd_cloexec(fileno(f));
+    return f;
 }
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 323fdcb..d50f79a 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -263,5 +263,6 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode);
 int pa_socket_cloexec(int domain, int type, int protocol);
 int pa_pipe_cloexec(int pipefd[2]);
 int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+FILE* pa_fopen_cloexec(const char *path, const char *mode);
 
 #endif

commit 88b72958bebd1770e45a4af2dc9fec75aaf1f2de
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 04:53:15 2009 +0100

    tdb: use O_CLOEXEC if available

diff --git a/src/pulsecore/database-tdb.c b/src/pulsecore/database-tdb.c
index b79d283..4e782d6 100644
--- a/src/pulsecore/database-tdb.c
+++ b/src/pulsecore/database-tdb.c
@@ -66,6 +66,39 @@ void pa_datum_free(pa_datum *d) {
     pa_zero(d);
 }
 
+static struct tdb_context *tdb_open_cloexec(
+        const char *name,
+        int hash_size,
+        int tdb_flags,
+        int open_flags,
+        mode_t mode) {
+
+    /* Mimics pa_open_cloexec() */
+
+    struct tdb_context *c;
+
+#ifdef O_NOCTTY
+    open_flags |= O_NOCTTY;
+#endif
+
+#ifdef O_CLOEXEC
+    errno = 0;
+    if ((c = tdb_open(name, hash_size, tdb_flags, open_flags | O_CLOEXEC, mode)))
+        goto finish;
+
+    if (errno != EINVAL)
+        return NULL;
+#endif
+
+    errno = 0;
+    if (!(c = tdb_open(name, hash_size, tdb_flags, open_flags, mode)))
+        return NULL;
+
+finish:
+    pa_make_fd_cloexec(tdb_fd(c));
+    return c;
+}
+
 pa_database* pa_database_open(const char *fn, pa_bool_t for_write) {
     struct tdb_context *c;
     char *path;
@@ -73,15 +106,7 @@ pa_database* pa_database_open(const char *fn, pa_bool_t for_write) {
     pa_assert(fn);
 
     path = pa_sprintf_malloc("%s.tdb", fn);
-    errno = 0;
-    c = tdb_open(path, 0, TDB_NOSYNC|TDB_NOLOCK,
-                 (for_write ? O_RDWR|O_CREAT : O_RDONLY)|O_NOCTTY
-#ifdef O_CLOEXEC
-                 |O_CLOEXEC
-#endif
-                 , 0644);
-
-    if (c)
+    if ((c = tdb_open_cloexec(path, 0, TDB_NOSYNC|TDB_NOLOCK, (for_write ? O_RDWR|O_CREAT : O_RDONLY), 0644)))
         pa_log_debug("Opened TDB database '%s'", path);
 
     pa_xfree(path);

commit 168be3830ae291dd819abebec813f76151487bb3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 04:54:19 2009 +0100

    use pa_fopen_cloexec() where applicable

diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 571faae..bfd5c11 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -577,7 +577,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
     c->config_file = NULL;
 
     f = filename ?
-        fopen(c->config_file = pa_xstrdup(filename), "r") :
+        pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") :
         pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file);
 
     if (!f && errno != ENOENT) {
@@ -652,7 +652,7 @@ FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) {
         else
             f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file);
     } else
-        f = fopen(c->default_script_file, "r");
+        f = pa_fopen_cloexec(c->default_script_file, "r");
 
     return f;
 }
diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c
index 6bd0f4f..c5ff456 100644
--- a/src/modules/module-cli.c
+++ b/src/modules/module-cli.c
@@ -105,7 +105,7 @@ int pa__init(pa_module*m) {
      * of log messages, particularly because if stdout and stderr are
      * dup'ed they share the same O_NDELAY, too. */
 
-    if ((fd = open("/dev/tty", O_RDWR|O_CLOEXEC|O_NONBLOCK)) >= 0) {
+    if ((fd = pa_open_cloexec("/dev/tty", O_RDWR|O_NONBLOCK, 0)) >= 0) {
         io = pa_iochannel_new(m->core->mainloop, fd, fd);
         pa_log_debug("Managed to open /dev/tty.");
     } else {
diff --git a/src/modules/module-default-device-restore.c b/src/modules/module-default-device-restore.c
index 27ae60e..94f589e 100644
--- a/src/modules/module-default-device-restore.c
+++ b/src/modules/module-default-device-restore.c
@@ -60,7 +60,7 @@ static void load(struct userdata *u) {
 
     if (u->core->default_sink)
         pa_log_info("Manually configured default sink, not overwriting.");
-    else if ((f = fopen(u->sink_filename, "r"))) {
+    else if ((f = pa_fopen_cloexec(u->sink_filename, "r"))) {
         char ln[256] = "";
         pa_sink *s;
 
@@ -81,7 +81,7 @@ static void load(struct userdata *u) {
 
     if (u->core->default_source)
         pa_log_info("Manually configured default source, not overwriting.");
-    else if ((f = fopen(u->source_filename, "r"))) {
+    else if ((f = pa_fopen_cloexec(u->source_filename, "r"))) {
         char ln[256] = "";
         pa_source *s;
 
@@ -108,7 +108,7 @@ static void save(struct userdata *u) {
         return;
 
     if (u->sink_filename) {
-        if ((f = fopen(u->sink_filename, "w"))) {
+        if ((f = pa_fopen_cloexec(u->sink_filename, "w"))) {
             pa_sink *s = pa_namereg_get_default_sink(u->core);
             fprintf(f, "%s\n", s ? s->name : "");
             fclose(f);
@@ -117,7 +117,7 @@ static void save(struct userdata *u) {
     }
 
     if (u->source_filename) {
-        if ((f = fopen(u->source_filename, "w"))) {
+        if ((f = pa_fopen_cloexec(u->source_filename, "w"))) {
             pa_source *s = pa_namereg_get_default_source(u->core);
             fprintf(f, "%s\n", s ? s->name : "");
             fclose(f);
diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c
index b1f24e1..1fe8eb8 100644
--- a/src/modules/module-detect.c
+++ b/src/modules/module-detect.c
@@ -63,7 +63,7 @@ static int detect_alsa(pa_core *c, int just_one) {
     FILE *f;
     int n = 0, n_sink = 0, n_source = 0;
 
-    if (!(f = fopen("/proc/asound/devices", "r"))) {
+    if (!(f = pa_fopen_cloexec("/proc/asound/devices", "r"))) {
 
         if (errno != ENOENT)
             pa_log_error("open(\"/proc/asound/devices\") failed: %s", pa_cstrerror(errno));
@@ -124,9 +124,9 @@ static int detect_oss(pa_core *c, int just_one) {
     FILE *f;
     int n = 0, b = 0;
 
-    if (!(f = fopen("/dev/sndstat", "r")) &&
-        !(f = fopen("/proc/sndstat", "r")) &&
-        !(f = fopen("/proc/asound/oss/sndstat", "r"))) {
+    if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) &&
+        !(f = pa_fopen_cloexec("/proc/sndstat", "r")) &&
+        !(f = pa_fopen_cloexec("/proc/asound/oss/sndstat", "r"))) {
 
         if (errno != ENOENT)
             pa_log_error("failed to open OSS sndstat device: %s", pa_cstrerror(errno));
diff --git a/src/modules/module-match.c b/src/modules/module-match.c
index 0bd781d..b1693f1 100644
--- a/src/modules/module-match.c
+++ b/src/modules/module-match.c
@@ -85,7 +85,7 @@ static int load_rules(struct userdata *u, const char *filename) {
     pa_assert(u);
 
     if (filename)
-        f = fopen(fn = pa_xstrdup(filename), "r");
+        f = pa_fopen_cloexec(fn = pa_xstrdup(filename), "r");
     else
         f = pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn);
 
diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c
index 1b1e9c1..a12f7c9 100644
--- a/src/modules/module-udev-detect.c
+++ b/src/modules/module-udev-detect.c
@@ -172,7 +172,7 @@ static pa_bool_t is_card_busy(const char *id) {
             if (status_file)
                 fclose(status_file);
 
-            if (!(status_file = fopen(sub_status, "r"))) {
+            if (!(status_file = pa_fopen_cloexec(sub_status, "r"))) {
                 pa_log_warn("Failed to open %s: %s", sub_status, pa_cstrerror(errno));
                 continue;
             }
diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c
index 41af3ba..b95023c 100644
--- a/src/modules/oss/oss-util.c
+++ b/src/modules/oss/oss-util.c
@@ -349,9 +349,9 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
     if ((n = get_device_number(dev)) < 0)
         return -1;
 
-    if (!(f = fopen("/dev/sndstat", "r")) &&
-        !(f = fopen("/proc/sndstat", "r")) &&
-        !(f = fopen("/proc/asound/oss/sndstat", "r"))) {
+    if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) &&
+        !(f = pa_fopen_cloexec("/proc/sndstat", "r")) &&
+        !(f = pa_fopen_cloexec("/proc/asound/oss/sndstat", "r"))) {
 
         if (errno != ENOENT)
             pa_log_warn("failed to open OSS sndstat device: %s", pa_cstrerror(errno));
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index 62c06f6..3eaca4d 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -110,7 +110,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
 
     if (filename) {
 
-        if (!(f = fopen(filename, "r"))) {
+        if (!(f = pa_fopen_cloexec(filename, "r"))) {
             pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno));
             goto finish;
         }
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index b57919a..82a44d8 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1804,7 +1804,7 @@ int pa_cli_command_execute_file(pa_core *c, const char *fn, pa_strbuf *buf, pa_b
     if (!fail)
         fail = &_fail;
 
-    if (!(f = fopen(fn, "r"))) {
+    if (!(f = pa_fopen_cloexec(fn, "r"))) {
         pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno));
         if (!*fail)
             ret = 0;
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index dd4a99e..34b4d6f 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -168,7 +168,7 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
     pa_assert(filename);
     pa_assert(t);
 
-    if (!f && !(f = fopen(filename, "r"))) {
+    if (!f && !(f = pa_fopen_cloexec(filename, "r"))) {
         if (errno == ENOENT) {
             pa_log_debug("Failed to open configuration file '%s': %s", filename, pa_cstrerror(errno));
             r = 0;
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 40da8f4..738bf06 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1600,7 +1600,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
         fn = buf;
 #endif
 
-        if ((f = fopen(fn, "r"))) {
+        if ((f = pa_fopen_cloexec(fn, "r"))) {
             if (result)
                 *result = pa_xstrdup(fn);
 
@@ -1634,7 +1634,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
         fn = buf;
 #endif
 
-        if ((f = fopen(fn, "r"))) {
+        if ((f = pa_fopen_cloexec(fn, "r"))) {
             if (result)
                 *result = pa_xstrdup(fn);
 
@@ -1661,7 +1661,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
         global = buf;
 #endif
 
-        if ((f = fopen(global, "r"))) {
+        if ((f = pa_fopen_cloexec(global, "r"))) {
 
             if (result)
                 *result = pa_xstrdup(global);
@@ -2560,7 +2560,7 @@ char *pa_machine_id(void) {
      * since it fits perfectly our needs and is not as volatile as the
      * hostname which might be set from dhcp. */
 
-    if ((f = fopen(PA_MACHINE_ID, "r"))) {
+    if ((f = pa_fopen_cloexec(PA_MACHINE_ID, "r"))) {
         char ln[34] = "", *r;
 
         r = fgets(ln, sizeof(ln)-1, f);
diff --git a/src/pulsecore/database-simple.c b/src/pulsecore/database-simple.c
index 1f4caf7..754930d 100644
--- a/src/pulsecore/database-simple.c
+++ b/src/pulsecore/database-simple.c
@@ -237,7 +237,7 @@ pa_database* pa_database_open(const char *fn, pa_bool_t for_write) {
     path = pa_sprintf_malloc("%s."CANONICAL_HOST".simple", fn);
     errno = 0;
 
-    f = fopen(path, "r");
+    f = pa_fopen_cloexec(path, "r");
 
     if (f || errno == ENOENT) { /* file not found is ok */
         db = pa_xnew0(simple_data, 1);
@@ -480,7 +480,7 @@ int pa_database_sync(pa_database *database) {
 
     errno = 0;
 
-    f = fopen(db->tmp_filename, "w");
+    f = pa_fopen_cloexec(db->tmp_filename, "w");
 
     if (!f)
         goto fail;
diff --git a/src/pulsecore/pid.c b/src/pulsecore/pid.c
index c92e831..213e798 100644
--- a/src/pulsecore/pid.c
+++ b/src/pulsecore/pid.c
@@ -143,7 +143,7 @@ static int proc_name_ours(pid_t pid, const char *procname) {
 
     pa_snprintf(bn, sizeof(bn), "/proc/%lu/stat", (unsigned long) pid);
 
-    if (!(f = fopen(bn, "r"))) {
+    if (!(f = pa_fopen_cloexec(bn, "r"))) {
         pa_log_info("Failed to open %s: %s", bn, pa_cstrerror(errno));
         return -1;
     } else {
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index a26dc87..74600de 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -1007,7 +1007,7 @@ void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn) {
 
     /* Only for debugging purposes */
 
-    f = fopen(fn, "a");
+    f = pa_fopen_cloexec(fn, "a");
 
     if (!f) {
         pa_log_warn("Failed to open '%s': %s", fn, pa_cstrerror(errno));

commit 75f7a971db587d554fffc15801a2d8f7497a2124
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 04:54:55 2009 +0100

    socket-util: allocate at least sizeof(sockaddr_storage) space

diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 651779f..0d0762d 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -85,12 +85,11 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
 
 #ifndef OS_IS_WIN32
     pa_assert_se(fstat(fd, &st) == 0);
-#endif
 
-#ifndef OS_IS_WIN32
     if (S_ISSOCK(st.st_mode)) {
 #endif
         union {
+            struct sockaddr_storage storage;
             struct sockaddr sa;
             struct sockaddr_in in;
 #ifdef HAVE_IPV6
@@ -315,6 +314,7 @@ pa_bool_t pa_socket_address_is_local(const struct sockaddr *sa) {
 pa_bool_t pa_socket_is_local(int fd) {
 
     union {
+        struct sockaddr_storage storage;
         struct sockaddr sa;
         struct sockaddr_in in;
 #ifdef HAVE_IPV6

commit a82c6b0cd5fa075b5a750e6416b7a7f0cd2508c7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 30 04:55:13 2009 +0100

    socket-util: drop redundant casts

diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 0d0762d..2cc9882 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -151,7 +151,7 @@ void pa_make_socket_low_delay(int fd) {
     pa_assert(fd >= 0);
 
     priority = 6;
-    if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0)
         pa_log_warn("SO_PRIORITY failed: %s", pa_cstrerror(errno));
 #endif
 }
@@ -165,9 +165,9 @@ void pa_make_tcp_socket_low_delay(int fd) {
     {
         int on = 1;
 #if defined(SOL_TCP)
-        if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0)
+        if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
 #else
-        if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0)
+        if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
 #endif
             pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno));
     }
@@ -177,9 +177,9 @@ void pa_make_tcp_socket_low_delay(int fd) {
     {
         int tos = IPTOS_LOWDELAY;
 #ifdef SOL_IP
-        if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0)
 #else
-        if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
 #endif
             pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
     }
@@ -195,9 +195,9 @@ void pa_make_udp_socket_low_delay(int fd) {
     {
         int tos = IPTOS_LOWDELAY;
 #ifdef SOL_IP
-        if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0)
 #else
-        if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
 #endif
             pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
     }
@@ -205,11 +205,11 @@ void pa_make_udp_socket_low_delay(int fd) {
 }
 
 int pa_socket_set_rcvbuf(int fd, size_t l) {
-    int bufsz = (int)l;
+    int bufsz = (int) l;
 
     pa_assert(fd >= 0);
 
-    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&bufsz, sizeof(bufsz)) < 0) {
+    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsz, sizeof(bufsz)) < 0) {
         pa_log_warn("SO_RCVBUF: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -218,12 +218,12 @@ int pa_socket_set_rcvbuf(int fd, size_t l) {
 }
 
 int pa_socket_set_sndbuf(int fd, size_t l) {
-    int bufsz = (int)l;
+    int bufsz = (int) l;
 
     pa_assert(fd >= 0);
 
-    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&bufsz, sizeof(bufsz)) < 0) {
-        pa_log("SO_SNDBUF: %s", pa_cstrerror(errno));
+    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &bufsz, sizeof(bufsz)) < 0) {
+        pa_log_warn("SO_SNDBUF: %s", pa_cstrerror(errno));
         return -1;
     }
 

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list