diff options
author | Chris Rankin <rankincj@yahoo.com> | 2011-10-03 21:27:57 +0100 |
---|---|---|
committer | Chris Rankin <rankincj@yahoo.com> | 2011-10-03 21:27:57 +0100 |
commit | 7a585790118e837ec788ac9b3e4cf6a381c61234 (patch) | |
tree | 9d60c2cce1518d75c9b0bd1bc31e278e74cc7f3f | |
parent | a39a950269d165f18448cc7d6da691bf14b9e03b (diff) | |
download | xine-lib-7a585790118e837ec788ac9b3e4cf6a381c61234.tar.gz xine-lib-7a585790118e837ec788ac9b3e4cf6a381c61234.tar.bz2 |
Set CLOEXEC flag on three more sockets.
There are two functions that actually set this flag:
int _x_set_file_close_on_exec()
int _x_set_socket_close_on_exec()
(We need two functions because file descriptors and sockets
are not the same under WIN32 - of course).
These function belong to libxine's internal API, i.e. they are
not available for use by plugins.
-rw-r--r-- | src/input/input_rtp.c | 4 | ||||
-rw-r--r-- | src/xine-engine/broadcaster.c | 5 | ||||
-rw-r--r-- | src/xine-engine/xine_private.h | 7 | ||||
-rw-r--r-- | src/xine-utils/utils.c | 22 |
4 files changed, 27 insertions, 11 deletions
diff --git a/src/input/input_rtp.c b/src/input/input_rtp.c index 175c61b41..c62c4ce9b 100644 --- a/src/input/input_rtp.c +++ b/src/input/input_rtp.c @@ -171,7 +171,7 @@ typedef struct { static int host_connect_attempt(struct in_addr ia, int port, const char *interface, xine_t *xine) { - int s=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + int s = xine_socket_cloexec(PF_INET, SOCK_DGRAM, IPPROTO_UDP); union { struct sockaddr_in in; struct sockaddr sa; @@ -180,7 +180,7 @@ static int host_connect_attempt(struct in_addr ia, int port, int multicast = 0; /* boolean, assume unicast */ if(s == -1) { - LOG_MSG(xine, _("socket(): %s.\n"), strerror(errno)); + LOG_MSG(xine, _("xine_socket_cloexec(): %s.\n"), strerror(errno)); return -1; } diff --git a/src/xine-engine/broadcaster.c b/src/xine-engine/broadcaster.c index f5ac0156f..0c2f2d4b2 100644 --- a/src/xine-engine/broadcaster.c +++ b/src/xine-engine/broadcaster.c @@ -64,6 +64,7 @@ #include <xine/xine_internal.h> #include <xine/buffer.h> #include <xine/xineutils.h> +#include "xine_private.h" #define QLEN 5 /* maximum connection queue length */ #define _BUFSIZ 512 @@ -228,6 +229,8 @@ static void *manager_loop (void *this_gen) { ssock = accept(this->msock, &(fsin.sa), &alen); if (ssock >= 0) { + _x_set_socket_close_on_exec(ssock); + /* identification string, helps demuxer probing */ if( sock_string_write(this->stream->xine, ssock,"master xine v1") > 0 ) { int *psock = malloc(sizeof(int)); @@ -308,7 +311,7 @@ broadcaster_t *_x_init_broadcaster(xine_stream_t *stream, int port) } servAddr; int msock, err; - msock = socket(PF_INET, SOCK_STREAM, 0); + msock = xine_socket_cloexec(PF_INET, SOCK_STREAM, 0); if( msock < 0 ) { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "broadcaster: error opening master socket.\n"); diff --git a/src/xine-engine/xine_private.h b/src/xine-engine/xine_private.h index 6c01d3a2d..a82f6a05f 100644 --- a/src/xine-engine/xine_private.h +++ b/src/xine-engine/xine_private.h @@ -94,4 +94,11 @@ void _x_audio_decoder_shutdown (xine_stream_t *stream) INTERNAL; */ void xine_probe_fast_memcpy(xine_t *xine) INTERNAL; +/** + * @brief Make file descriptors and sockets uninheritable + */ +int _x_set_file_close_on_exec(int fd) INTERNAL; + +int _x_set_socket_close_on_exec(int s) INTERNAL; + #endif diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 61f2d71c5..bc5f1a228 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -32,6 +32,7 @@ #ifdef _MSC_VER #include <xine/xine_internal.h> #endif +#include "xine_private.h" #include <errno.h> #include <pwd.h> @@ -726,7 +727,7 @@ char *xine_strcat_realloc (char **dest, char *append) } -static int set_close_on_execute(int fd) +int _x_set_file_close_on_exec(int fd) { #ifndef WIN32 return fcntl(fd, F_SETFD, FD_CLOEXEC); @@ -735,13 +736,22 @@ static int set_close_on_execute(int fd) #endif } +int _x_set_socket_close_on_exec(int s) +{ +#ifndef WIN32 + return fcntl(s, F_SETFD, FD_CLOEXEC); +#else + return SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); +#endif +} + int xine_open_cloexec(const char *name, int flags) { int fd = open(name, (flags | O_CLOEXEC)); if (fd >= 0) { - set_close_on_execute(fd); + _x_set_file_close_on_exec(fd); } return fd; @@ -752,7 +762,7 @@ int xine_create_cloexec(const char *name, int flags, mode_t mode) int fd = open(name, (flags | O_CREAT | O_CLOEXEC), mode); if (fd >= 0) { - set_close_on_execute(fd); + _x_set_file_close_on_exec(fd); } return fd; @@ -763,11 +773,7 @@ int xine_socket_cloexec(int domain, int type, int protocol) int s = socket(domain, type, protocol); if (s >= 0) { -#ifndef WIN32 - fcntl(s, F_SETFD, FD_CLOEXEC); -#else - SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); -#endif + _x_set_socket_close_on_exec(s); } return s; |