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
+2 -5
View File
@@ -19,6 +19,7 @@
#include "event_pipe.h"
#include "utils.h"
#include "fd_util.h"
#include <stdbool.h>
#include <assert.h>
@@ -84,11 +85,7 @@ void event_pipe_init(void)
GIOChannel *channel;
int ret;
#ifdef WIN32
ret = _pipe(event_pipe, 512, _O_BINARY);
#else
ret = pipe(event_pipe);
#endif
ret = pipe_cloexec(event_pipe);
if (ret < 0)
g_error("Couldn't open pipe: %s", strerror(errno));
#ifndef WIN32