From cba782a23ee5c9c668e02f9c6d95acba70464d18 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 01:48:45 +0100 Subject: Add CLOEXEC support for VDR plugin, plus a few extra descriptors. --- src/vdr/input_vdr.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/vdr') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index ed478c80d..ac8c8c795 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -1919,7 +1919,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) filename = strdup(filename); _x_mrl_unescape (filename); - this->fh = open(filename, O_RDONLY | O_NONBLOCK); + this->fh = open_cloexec(filename, O_RDONLY | O_NONBLOCK); lprintf("filename '%s'\n", filename); @@ -1960,7 +1960,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) char *filename_control = 0; asprintf(&filename_control, "%s.control", filename); - this->fh_control = open(filename_control, O_RDONLY); + this->fh_control = open_cloexec(filename_control, O_RDONLY); if (this->fh_control == -1) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, @@ -1980,7 +1980,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) char *filename_result = 0; asprintf(&filename_result, "%s.result", filename); - this->fh_result = open(filename_result, O_WRONLY); + this->fh_result = open_cloexec(filename_result, O_WRONLY); if (this->fh_result == -1) { perror("failed"); @@ -2002,7 +2002,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) char *filename_event = 0; asprintf(&filename_event, "%s.event", filename); - this->fh_event = open(filename_event, O_WRONLY); + this->fh_event = open_cloexec(filename_event, O_WRONLY); if (this->fh_event == -1) { perror("failed"); @@ -2038,6 +2038,16 @@ static int vdr_plugin_open_socket(vdr_input_plugin_t *this, struct hostent *host return -1; } +#ifndef WIN32 + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable (%s)\n", strerror(errno)); + } +#else + if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable\n"); + } +#endif + iaddr.s_addr = *((unsigned int *)host->h_addr_list[0]); sain.sin_port = htons(port); -- cgit v1.2.3 From a39a950269d165f18448cc7d6da691bf14b9e03b Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 12:38:45 +0100 Subject: Prefix open_cloexec() and create_cloexec() with xine_, and add new xine_socket_cloexec() function. --- src/vdr/input_vdr.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/vdr') diff --git a/src/vdr/input_vdr.c b/src/vdr/input_vdr.c index ac8c8c795..2b0329867 100644 --- a/src/vdr/input_vdr.c +++ b/src/vdr/input_vdr.c @@ -1919,7 +1919,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) filename = strdup(filename); _x_mrl_unescape (filename); - this->fh = open_cloexec(filename, O_RDONLY | O_NONBLOCK); + this->fh = xine_open_cloexec(filename, O_RDONLY | O_NONBLOCK); lprintf("filename '%s'\n", filename); @@ -1960,7 +1960,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) char *filename_control = 0; asprintf(&filename_control, "%s.control", filename); - this->fh_control = open_cloexec(filename_control, O_RDONLY); + this->fh_control = xine_open_cloexec(filename_control, O_RDONLY); if (this->fh_control == -1) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, @@ -1980,7 +1980,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) char *filename_result = 0; asprintf(&filename_result, "%s.result", filename); - this->fh_result = open_cloexec(filename_result, O_WRONLY); + this->fh_result = xine_open_cloexec(filename_result, O_WRONLY); if (this->fh_result == -1) { perror("failed"); @@ -2002,7 +2002,7 @@ static int vdr_plugin_open_fifo_mrl(input_plugin_t *this_gen) char *filename_event = 0; asprintf(&filename_event, "%s.event", filename); - this->fh_event = open_cloexec(filename_event, O_WRONLY); + this->fh_event = xine_open_cloexec(filename_event, O_WRONLY); if (this->fh_event == -1) { perror("failed"); @@ -2030,7 +2030,7 @@ static int vdr_plugin_open_socket(vdr_input_plugin_t *this, struct hostent *host struct sockaddr_in sain; struct in_addr iaddr; - if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) + if ((fd = xine_socket_cloexec(PF_INET, SOCK_STREAM, 0)) == -1) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _("%s: failed to create socket for port %d (%s)\n"), LOG_MODULE, @@ -2038,16 +2038,6 @@ static int vdr_plugin_open_socket(vdr_input_plugin_t *this, struct hostent *host return -1; } -#ifndef WIN32 - if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable (%s)\n", strerror(errno)); - } -#else - if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "Failed to make socket uninheritable\n"); - } -#endif - iaddr.s_addr = *((unsigned int *)host->h_addr_list[0]); sain.sin_port = htons(port); -- cgit v1.2.3