set the close-on-exec flag on all file descriptors

Added the "fd_util" library, which attempts to use the new thread-safe
Linux system calls pipe2(), accept4() and the options O_CLOEXEC,
SOCK_CLOEXEC.  Without these, it falls back to FD_CLOEXEC, which is
not thread safe.

This is particularly important for the "pipe" output plugin (and
others, such as JACK/PulseAudio), because we were heavily leaking file
descriptors to child processes.
This commit is contained in:
Max Kellermann
2009-11-07 18:55:16 +01:00
parent 9b21152600
commit e3af0032b2
17 changed files with 271 additions and 24 deletions

@@ -20,6 +20,7 @@
#include "config.h" /* must be first for large file support */
#include "input/file_input_plugin.h"
#include "input_plugin.h"
#include "fd_util.h"
#include <sys/stat.h>
#include <fcntl.h>
@@ -50,7 +51,7 @@ input_file_open(struct input_stream *is, const char *filename)
*slash = '\0';
}
fd = open(pathname, O_RDONLY);
fd = open_cloexec(pathname, O_RDONLY);
if (fd < 0) {
is->error = errno;
g_debug("Failed to open \"%s\": %s",