diff options
author | Chris Rankin <rankincj@yahoo.com> | 2011-10-01 14:14:27 +0100 |
---|---|---|
committer | Chris Rankin <rankincj@yahoo.com> | 2011-10-01 14:14:27 +0100 |
commit | 62a669d9f04e83debe729347617a935707badc7e (patch) | |
tree | 3d71d5520db6c429666abf1823d2d20b082af97d /src/xine-engine | |
parent | 8ba50d7512e71ce2fa441f8e738459df21cec2ae (diff) | |
download | xine-lib-62a669d9f04e83debe729347617a935707badc7e.tar.gz xine-lib-62a669d9f04e83debe729347617a935707badc7e.tar.bz2 |
Mark simple file and socket descriptors as uninheritable.
This patch creates two utility functions:
int open_cloexec(pathname, flags)
int create_cloexec(pathname, flags, mode)
These return a file descriptor with the CLOEXEC flag set, to ensure
that the descriptor is not inherited across a fork/exec operation.
The sockets returned by:
_x_io_tcp_connect_ipv4()
_x_io_tcp_connect()
now also have their CLOEXEC flag set.
Diffstat (limited to 'src/xine-engine')
-rw-r--r-- | src/xine-engine/io_helper.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/xine-engine/io_helper.c b/src/xine-engine/io_helper.c index b06c47709..5bcd95c63 100644 --- a/src/xine-engine/io_helper.c +++ b/src/xine-engine/io_helper.c @@ -67,6 +67,16 @@ static int _x_io_tcp_connect_ipv4(xine_stream_t *stream, const char *host, int p } #ifndef WIN32 + if (fcntl(s, F_SETFD, FD_CLOEXEC) < 0) { + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable (%s)\n", strerror(errno)); + } +#else + if (!SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0)) { + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable\n"); + } +#endif + +#ifndef WIN32 if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1) { _x_message(stream, XINE_MSG_CONNECTION_REFUSED, "can't put socket in non-blocking mode", strerror(errno), NULL); return -1; @@ -152,6 +162,16 @@ int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) { continue; } +#ifndef WIN32 + if (fcntl(s, F_SETFD, FD_CLOEXEC) < 0) { + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable (%s)\n", strerror(errno)); + } +#else + if (!SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0)) { + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable\n"); + } +#endif + /* * Enable the non-blocking features only when there's no other * address, allowing to use other addresses if available. |