summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Rankin <rankincj@yahoo.com>2011-10-03 12:38:45 +0100
committerChris Rankin <rankincj@yahoo.com>2011-10-03 12:38:45 +0100
commita39a950269d165f18448cc7d6da691bf14b9e03b (patch)
tree2ff0626b06e3e87cb9f3d7678af4859b5d65b594 /src
parentcba782a23ee5c9c668e02f9c6d95acba70464d18 (diff)
downloadxine-lib-a39a950269d165f18448cc7d6da691bf14b9e03b.tar.gz
xine-lib-a39a950269d165f18448cc7d6da691bf14b9e03b.tar.bz2
Prefix open_cloexec() and create_cloexec() with xine_, and add new xine_socket_cloexec() function.
Diffstat (limited to 'src')
-rw-r--r--src/audio_dec/xine_a52_decoder.c2
-rw-r--r--src/audio_out/audio_file_out.c2
-rw-r--r--src/audio_out/audio_oss_out.c8
-rw-r--r--src/audio_out/audio_sun_out.c6
-rw-r--r--src/dxr3/dxr3_decode_spu.c2
-rw-r--r--src/dxr3/dxr3_decode_video.c4
-rw-r--r--src/dxr3/dxr3_scr.c2
-rw-r--r--src/dxr3/video_out_dxr3.c8
-rw-r--r--src/input/input_cdda.c2
-rw-r--r--src/input/input_dvb.c16
-rw-r--r--src/input/input_file.c2
-rw-r--r--src/input/input_net.c32
-rw-r--r--src/input/input_pvr.c10
-rw-r--r--src/input/input_stdin_fifo.c6
-rw-r--r--src/input/input_v4l.c8
-rw-r--r--src/input/input_vcd.c6
-rw-r--r--src/input/media_helper.c2
-rw-r--r--src/libw32dll/wine/registry.c4
-rw-r--r--src/vdr/input_vdr.c20
-rw-r--r--src/video_out/video_out_fb.c6
-rw-r--r--src/video_out/video_out_pgx64.c2
-rw-r--r--src/video_out/video_out_vidix.c2
-rw-r--r--src/xine-engine/io_helper.c24
-rw-r--r--src/xine-utils/utils.c21
24 files changed, 79 insertions, 118 deletions
diff --git a/src/audio_dec/xine_a52_decoder.c b/src/audio_dec/xine_a52_decoder.c
index 683b4dd1e..85e20d1d4 100644
--- a/src/audio_dec/xine_a52_decoder.c
+++ b/src/audio_dec/xine_a52_decoder.c
@@ -783,7 +783,7 @@ static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stre
this->a52_flags_map[i] |= A52_ADJUST_LEVEL;
*/
#ifdef DEBUG_A52
- a52file = create_cloexec("test.a52", O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
+ a52file = xine_create_cloexec("test.a52", O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
#endif
return &this->audio_decoder;
}
diff --git a/src/audio_out/audio_file_out.c b/src/audio_out/audio_file_out.c
index 352e3421e..c8fe51f72 100644
--- a/src/audio_out/audio_file_out.c
+++ b/src/audio_out/audio_file_out.c
@@ -115,7 +115,7 @@ static int ao_file_open(ao_driver_t *this_gen, uint32_t bits, uint32_t rate, int
if (!this->fname)
this->fname = "xine-out.wav";
- this->fd = create_cloexec(this->fname, O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
+ this->fd = xine_create_cloexec(this->fname, O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (this->fd == -1) {
xprintf (this->xine, XINE_VERBOSITY_LOG, "audio_file_out: Failed to open file '%s': %s\n",
diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c
index 3c2364798..cf1608a25 100644
--- a/src/audio_out/audio_oss_out.c
+++ b/src/audio_out/audio_oss_out.c
@@ -190,7 +190,7 @@ static int ao_oss_open(ao_driver_t *this_gen,
* open audio device
*/
- this->audio_fd = open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
+ this->audio_fd = xine_open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
if (this->audio_fd < 0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
_("audio_oss_out: Opening audio device %s: %s\n"), this->audio_dev, strerror(errno));
@@ -781,7 +781,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da
xprintf(class->xine, XINE_VERBOSITY_LOG,
_("audio_oss_out: using device >%s<\n"), this->audio_dev);
- audio_fd = open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
+ audio_fd = xine_open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
if (audio_fd < 0) {
xprintf(class->xine, XINE_VERBOSITY_LOG,
@@ -894,7 +894,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da
_("audio_oss_out: Audio driver realtime sync disabled...\n"
"audio_oss_out: ...probing output buffer size: %d bytes\naudio_oss_out: ...there may be audio/video synchronization issues\n"), this->buffer_size);
- audio_fd = open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
+ audio_fd = xine_open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
if(audio_fd < 0)
{
@@ -1048,7 +1048,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da
}
_x_assert(this->mixer.name);
- this->mixer.fd = open_cloexec(this->mixer.name, O_RDONLY);
+ this->mixer.fd = xine_open_cloexec(this->mixer.name, O_RDONLY);
if(this->mixer.fd != -1) {
diff --git a/src/audio_out/audio_sun_out.c b/src/audio_out/audio_sun_out.c
index 029545544..34d2f14ec 100644
--- a/src/audio_out/audio_sun_out.c
+++ b/src/audio_out/audio_sun_out.c
@@ -160,7 +160,7 @@ static int realtime_samplecounter_available(xine_t *xine, char *dev)
if (silence == NULL)
goto error;
- if ((fd = open_cloexec(dev, O_WRONLY|O_NONBLOCK)) < 0)
+ if ((fd = xine_open_cloexec(dev, O_WRONLY|O_NONBLOCK)) < 0)
goto error;
/* We wanted non blocking open but now put it back to normal */
@@ -449,7 +449,7 @@ static int ao_sun_open(ao_driver_t *this_gen,
* open audio device
*/
- this->audio_fd = open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
+ this->audio_fd = xine_open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK);
if(this->audio_fd < 0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
_("audio_sun_out: opening audio device %s failed: %s\n"), this->audio_dev, strerror(errno));
@@ -940,7 +940,7 @@ static ao_driver_t *ao_sun_open_plugin (audio_driver_class_t *class_gen, const v
* open the device
*/
this->audio_dev = devname;
- this->audio_fd = open_cloexec(devname, O_WRONLY|O_NONBLOCK);
+ this->audio_fd = xine_open_cloexec(devname, O_WRONLY|O_NONBLOCK);
if(this->audio_fd < 0)
{
diff --git a/src/dxr3/dxr3_decode_spu.c b/src/dxr3/dxr3_decode_spu.c
index 82dfd2f91..0dc024253 100644
--- a/src/dxr3/dxr3_decode_spu.c
+++ b/src/dxr3/dxr3_decode_spu.c
@@ -236,7 +236,7 @@ static spu_decoder_t *dxr3_spudec_open_plugin(spu_decoder_class_t *class_gen, xi
else {
/* open dxr3 spu device */
snprintf(tmpstr, sizeof(tmpstr), "/dev/em8300_sp-%d", this->devnum);
- if ((this->fd_spu = open_cloexec(tmpstr, O_WRONLY)) < 0) {
+ if ((this->fd_spu = xine_open_cloexec(tmpstr, O_WRONLY)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("dxr3_decode_spu: Failed to open spu device %s (%s)\n"), tmpstr, strerror(errno));
pthread_mutex_unlock(&this->dxr3_vo->spu_device_lock);
diff --git a/src/dxr3/dxr3_decode_video.c b/src/dxr3/dxr3_decode_video.c
index a5af67b36..ec28b4648 100644
--- a/src/dxr3/dxr3_decode_video.c
+++ b/src/dxr3/dxr3_decode_video.c
@@ -227,7 +227,7 @@ static video_decoder_t *dxr3_open_plugin(video_decoder_class_t *class_gen, xine_
/* open later, because dxr3_video_out might have it open until we request a frame */
this->fd_video = -1;
- if ((this->fd_control = open_cloexec(tmpstr, O_WRONLY)) < 0) {
+ if ((this->fd_control = xine_open_cloexec(tmpstr, O_WRONLY)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("dxr3_decode_video: Failed to open control device %s (%s)\n"), tmpstr, strerror(errno));
free(this);
@@ -508,7 +508,7 @@ static void dxr3_decode_data(video_decoder_t *this_gen, buf_element_t *buf)
/* open the device for the decoder */
snprintf (tmpstr, sizeof(tmpstr), "/dev/em8300_mv-%d", this->devnum);
- if ((this->fd_video = open_cloexec(tmpstr, O_WRONLY)) < 0) {
+ if ((this->fd_video = xine_open_cloexec(tmpstr, O_WRONLY)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("dxr3_decode_video: Failed to open video device %s (%s)\n"), tmpstr, strerror(errno));
return;
diff --git a/src/dxr3/dxr3_scr.c b/src/dxr3/dxr3_scr.c
index ad6d98b50..b38a88444 100644
--- a/src/dxr3/dxr3_scr.c
+++ b/src/dxr3/dxr3_scr.c
@@ -75,7 +75,7 @@ dxr3_scr_t *dxr3_scr_init(xine_t *xine)
devnum = xine->config->register_num(xine->config,
CONF_KEY, 0, CONF_NAME, CONF_HELP, 10, NULL, NULL);
snprintf(tmpstr, sizeof(tmpstr), "/dev/em8300-%d", devnum);
- if ((this->fd_control = open_cloexec(tmpstr, O_WRONLY)) < 0) {
+ if ((this->fd_control = xine_open_cloexec(tmpstr, O_WRONLY)) < 0) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
"dxr3_scr: Failed to open control device %s (%s)\n", tmpstr, strerror(errno));
free(this);
diff --git a/src/dxr3/video_out_dxr3.c b/src/dxr3/video_out_dxr3.c
index dfab75024..a5d75cc69 100644
--- a/src/dxr3/video_out_dxr3.c
+++ b/src/dxr3/video_out_dxr3.c
@@ -271,7 +271,7 @@ static vo_driver_t *dxr3_vo_open_plugin(video_driver_class_t *class_gen, const v
snprintf(tmpstr, sizeof(tmpstr), "/dev/em8300-%d", class->devnum);
llprintf(LOG_VID, "Entering video init, devname = %s.\n", tmpstr);
- if ((this->fd_control = open_cloexec(tmpstr, O_WRONLY)) < 0) {
+ if ((this->fd_control = xine_open_cloexec(tmpstr, O_WRONLY)) < 0) {
xprintf(this->class->xine, XINE_VERBOSITY_LOG,
_("video_out_dxr3: Failed to open control device %s (%s)\n"), tmpstr, strerror(errno));
@@ -280,7 +280,7 @@ static vo_driver_t *dxr3_vo_open_plugin(video_driver_class_t *class_gen, const v
}
snprintf (tmpstr, sizeof(tmpstr), "/dev/em8300_mv-%d", class->devnum);
- if ((this->fd_video = open_cloexec(tmpstr, O_WRONLY | O_SYNC )) < 0) {
+ if ((this->fd_video = xine_open_cloexec(tmpstr, O_WRONLY | O_SYNC )) < 0) {
xprintf(this->class->xine, XINE_VERBOSITY_LOG,
_("video_out_dxr3: Failed to open video device %s (%s)\n"), tmpstr, strerror(errno));
return 0;
@@ -637,7 +637,7 @@ static void dxr3_update_frame_format(vo_driver_t *this_gen, vo_frame_t *frame_ge
/* open the device for the encoder */
snprintf(tmpstr, sizeof(tmpstr), "/dev/em8300_mv-%d", this->class->devnum);
- if ((this->fd_video = open_cloexec(tmpstr, O_WRONLY)) < 0)
+ if ((this->fd_video = xine_open_cloexec(tmpstr, O_WRONLY)) < 0)
xprintf(this->class->xine, XINE_VERBOSITY_DEBUG,
"video_out_dxr3: Failed to open video device %s (%s)\n", tmpstr, strerror(errno));
@@ -832,7 +832,7 @@ static void dxr3_overlay_end(vo_driver_t *this_gen, vo_frame_t *frame_gen)
/* try to open the dxr3 spu device */
if (!this->fd_spu) {
snprintf (tmpstr, sizeof(tmpstr), "/dev/em8300_sp-%d", this->class->devnum);
- if ((this->fd_spu = open_cloexec(tmpstr, O_WRONLY)) < 0) {
+ if ((this->fd_spu = xine_open_cloexec(tmpstr, O_WRONLY)) < 0) {
xprintf(this->class->xine, XINE_VERBOSITY_DEBUG,
"video_out_dxr3: Failed to open spu device %s (%s)\n"
"video_out_dxr3: Overlays are not available\n", tmpstr, strerror(errno));
diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c
index 6342fb5eb..20129706d 100644
--- a/src/input/input_cdda.c
+++ b/src/input/input_cdda.c
@@ -1938,7 +1938,7 @@ static int cdda_open(cdda_input_plugin_t *this_gen,
/* We use O_NONBLOCK for when /proc/sys/dev/cdrom/check_media is at 1 on
* Linux systems */
- fd = open_cloexec(cdda_device, O_RDONLY | O_NONBLOCK);
+ fd = xine_open_cloexec(cdda_device, O_RDONLY | O_NONBLOCK);
if (fd == -1) {
return -1;
}
diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c
index 6a984ab14..0fac0290a 100644
--- a/src/input/input_dvb.c
+++ b/src/input/input_dvb.c
@@ -592,7 +592,7 @@ static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter)
asprintf(&video_device,"/dev/dvb/adapter%i/video0",this->adapter_num);
asprintf(&frontend_device,"/dev/dvb/adapter%i/frontend0",this->adapter_num);
- if ((this->fd_frontend = open_cloexec(frontend_device, O_RDWR)) < 0) {
+ if ((this->fd_frontend = xine_open_cloexec(frontend_device, O_RDWR)) < 0) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG, "FRONTEND DEVICE: %s\n", strerror(errno));
tuner_dispose(this);
this = NULL;
@@ -608,7 +608,7 @@ static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter)
}
for (x = 0; x < MAX_FILTERS; x++) {
- this->fd_pidfilter[x] = open_cloexec(this->demux_device, O_RDWR);
+ this->fd_pidfilter[x] = xine_open_cloexec(this->demux_device, O_RDWR);
if (this->fd_pidfilter[x] < 0) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG, "DEMUX DEVICE PIDfilter: %s\n", strerror(errno));
tuner_dispose(this);
@@ -617,7 +617,7 @@ static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter)
}
}
for (x = 0; x < MAX_SUBTITLES; x++) {
- this->fd_subfilter[x] = open_cloexec(this->demux_device, O_RDWR);
+ this->fd_subfilter[x] = xine_open_cloexec(this->demux_device, O_RDWR);
if (this->fd_subfilter[x] < 0) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG, "DEMUX DEVICE Subtitle filter: %s\n", strerror(errno));
}
@@ -638,7 +638,7 @@ static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter)
if(this->feinfo.type==FE_OFDM) xprintf(this->xine,XINE_VERBOSITY_DEBUG,"TER Card\n");
if(this->feinfo.type==FE_ATSC) xprintf(this->xine,XINE_VERBOSITY_DEBUG,"US Card\n");
- if ((test_video=open_cloexec(video_device, O_RDWR)) < 0) {
+ if ((test_video=xine_open_cloexec(video_device, O_RDWR)) < 0) {
xprintf(this->xine,XINE_VERBOSITY_DEBUG,"input_dvb: Card has no hardware decoder\n");
}else{
xprintf(this->xine,XINE_VERBOSITY_DEBUG,"input_dvb: Card HAS HARDWARE DECODER\n");
@@ -2126,7 +2126,7 @@ static int switch_channel(dvb_input_plugin_t *this, int channel) {
for (x = 0; x < MAX_FILTERS; x++) {
close(this->tuner->fd_pidfilter[x]);
- this->tuner->fd_pidfilter[x] = open_cloexec(this->tuner->demux_device, O_RDWR);
+ this->tuner->fd_pidfilter[x] = xine_open_cloexec(this->tuner->demux_device, O_RDWR);
}
if (!tuner_set_channel (this, &this->channels[channel])) {
@@ -2160,7 +2160,7 @@ static int switch_channel(dvb_input_plugin_t *this, int channel) {
this->channel = channel;
- this->fd = open_cloexec(this->tuner->dvr_device, O_RDONLY | O_NONBLOCK);
+ this->fd = xine_open_cloexec(this->tuner->dvr_device, O_RDONLY | O_NONBLOCK);
this->tuned_in = 1;
pthread_mutex_unlock (&this->channel_change_mutex);
@@ -2234,7 +2234,7 @@ static void do_record (dvb_input_plugin_t *this) {
}
/* start recording */
- this->record_fd = create_cloexec(filename, O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ this->record_fd = xine_create_cloexec(filename, O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
this->stream->osd_renderer->clear (this->rec_osd);
@@ -2980,7 +2980,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
return 0;
}
- if ((this->fd = open_cloexec(this->tuner->dvr_device, O_RDONLY |O_NONBLOCK)) < 0) {
+ if ((this->fd = xine_open_cloexec(this->tuner->dvr_device, O_RDONLY |O_NONBLOCK)) < 0) {
xprintf(this->class->xine, XINE_VERBOSITY_LOG,
_("input_dvb: cannot open dvr device '%s'\n"), this->tuner->dvr_device);
return 0;
diff --git a/src/input/input_file.c b/src/input/input_file.c
index f9232b389..4c5e3e563 100644
--- a/src/input/input_file.c
+++ b/src/input/input_file.c
@@ -359,7 +359,7 @@ static int file_plugin_open (input_plugin_t *this_gen ) {
else
filename = strdup(this->mrl); /* NEVER unescape plain file names! */
- this->fh = open_cloexec(filename, O_RDONLY|O_BINARY);
+ this->fh = xine_open_cloexec(filename, O_RDONLY|O_BINARY);
if (this->fh == -1) {
if (errno == EACCES) {
diff --git a/src/input/input_net.c b/src/input/input_net.c
index f44db8301..edbe73b08 100644
--- a/src/input/input_net.c
+++ b/src/input/input_net.c
@@ -115,25 +115,13 @@ static int host_connect_attempt_ipv4(struct in_addr ia, int port, xine_t *xine)
int s;
struct sockaddr_in sin;
- s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ s = xine_socket_cloexec(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s==-1) {
xine_log(xine, XINE_LOG_MSG,
_("input_net: socket(): %s\n"), strerror(errno));
return -1;
}
-#ifndef WIN32
- if (fcntl(s, F_SETFD, FD_CLOEXEC) < 0) {
- xine_log(xine, XINE_LOG_MSG,
- _("input_net: Failed to make socket uninheritable (%s)\n"),
- strerror(errno));
- }
-#else
- if (!SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0)) {
- xine_log(xine, XINE_LOG_MSG, "Failed to make socket uninheritable\n");
- }
-#endif
-
sin.sin_family = AF_INET;
sin.sin_addr = ia;
sin.sin_port = htons(port);
@@ -155,28 +143,14 @@ static int host_connect_attempt_ipv4(struct in_addr ia, int port, xine_t *xine)
#else
static int host_connect_attempt(int family, struct sockaddr* sin, int addrlen, xine_t *xine) {
- int s;
-
- s = socket(family, SOCK_STREAM, IPPROTO_TCP);
- if (s==-1) {
+ int s = xine_socket_cloexec(family, SOCK_STREAM, IPPROTO_TCP);
+ if (s == -1) {
xine_log(xine, XINE_LOG_MSG,
_("input_net: socket(): %s\n"), strerror(errno));
return -1;
}
#ifndef WIN32
- if (fcntl(s, F_SETFD, FD_CLOEXEC) < 0) {
- xine_log(xine, XINE_LOG_MSG,
- _("input_net: Failed to make socket uninheritable (%s)\n"),
- strerror(errno));
- }
-#else
- if (!SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0)) {
- xine_log(xine, XINE_LOG_MSG, "Failed to make socket uninheritable\n");
- }
-#endif
-
-#ifndef WIN32
if (connect(s, sin, addrlen)==-1 && errno != EINPROGRESS)
#else
if (connect(s, sin, addrlen)==-1 && WSAGetLastError() != WSAEINPROGRESS)
diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c
index 7e04c0bc9..53c104299 100644
--- a/src/input/input_pvr.c
+++ b/src/input/input_pvr.c
@@ -584,7 +584,7 @@ static int pvr_break_rec_page (pvr_input_plugin_t *this) {
lprintf("opening pvr file for writing (%s)\n", filename);
- this->rec_fd = create_cloexec(filename, O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ this->rec_fd = xine_create_cloexec(filename, O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if( this->rec_fd == -1 ) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("input_pvr: error creating pvr file (%s)\n"), filename);
@@ -741,7 +741,7 @@ static int pvr_play_file(pvr_input_plugin_t *this, fifo_buffer_t *fifo, uint8_t
lprintf("opening pvr file for reading (%s)\n", filename);
- this->play_fd = open_cloexec(filename, O_RDONLY);
+ this->play_fd = xine_open_cloexec(filename, O_RDONLY);
if( this->play_fd == -1 ) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("input_pvr: error opening pvr file (%s)\n"), filename);
@@ -1009,7 +1009,7 @@ static void pvr_event_handler (pvr_input_plugin_t *this) {
/* as of ivtv 0.10.6: must close and reopen to set input */
close(this->dev_fd);
- this->dev_fd = open_cloexec(this->class->devname, O_RDWR);
+ this->dev_fd = xine_open_cloexec(this->class->devname, O_RDWR);
if (this->dev_fd < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
"input_pvr: error opening device %s\n", this->class->devname );
@@ -1156,7 +1156,7 @@ static void pvr_event_handler (pvr_input_plugin_t *this) {
/* how lame. we must close and reopen to change bitrate. */
close(this->dev_fd);
- this->dev_fd = open_cloexec(this->class->devname, O_RDWR);
+ this->dev_fd = xine_open_cloexec(this->class->devname, O_RDWR);
if (this->dev_fd == -1) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("input_pvr: error opening device %s\n"), this->class->devname );
@@ -1416,7 +1416,7 @@ static int pvr_plugin_open (input_plugin_t *this_gen ) {
this->saved_id = 0;
- this->dev_fd = open_cloexec(this->class->devname, O_RDWR);
+ this->dev_fd = xine_open_cloexec(this->class->devname, O_RDWR);
if (this->dev_fd == -1) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("input_pvr: error opening device %s\n"), this->class->devname );
diff --git a/src/input/input_stdin_fifo.c b/src/input/input_stdin_fifo.c
index 02c3d526a..e0aecdc39 100644
--- a/src/input/input_stdin_fifo.c
+++ b/src/input/input_stdin_fifo.c
@@ -251,10 +251,10 @@ static int stdin_plugin_open (input_plugin_t *this_gen ) {
lprintf ("trying to open '%s'...\n", this->mrl);
if (this->fh == -1) {
- char *filename;
+ const char *filename;
- filename = (char *) &this->mrl[5];
- this->fh = open_cloexec(filename, FILE_FLAGS);
+ filename = (const char *) &this->mrl[5];
+ this->fh = xine_open_cloexec(filename, FILE_FLAGS);
lprintf("filename '%s'\n", filename);
diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c
index 3947e6ab4..c91b273e7 100644
--- a/src/input/input_v4l.c
+++ b/src/input/input_v4l.c
@@ -822,7 +822,7 @@ static int open_radio_capture_device(v4l_input_plugin_t *this)
entry = this->stream->xine->config->lookup_entry(this->stream->xine->config,
"media.video4linux.radio_device");
- if((this->radio_fd = open_cloexec(entry->str_value, O_RDWR)) < 0) {
+ if((this->radio_fd = xine_open_cloexec(entry->str_value, O_RDWR)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
"input_v4l: error opening v4l device (%s): %s\n",
entry->str_value, strerror(errno));
@@ -875,7 +875,7 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
"media.video4linux.video_device");
/* Try to open the video device */
- if((this->video_fd = open_cloexec(entry->str_value, O_RDWR)) < 0) {
+ if((this->video_fd = xine_open_cloexec(entry->str_value, O_RDWR)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
"input_v4l: error opening v4l device (%s): %s\n",
entry->str_value, strerror(errno));
@@ -1799,7 +1799,7 @@ static input_plugin_t *v4l_class_get_video_instance (input_class_t *cls_gen,
"media.video4linux.video_device");
/* Try to open the video device */
- if((this->video_fd = open_cloexec(entry->str_value, O_RDWR)) < 0) {
+ if((this->video_fd = xine_open_cloexec(entry->str_value, O_RDWR)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
"input_v4l: error opening v4l device (%s): %s\n",
entry->str_value, strerror(errno));
@@ -1862,7 +1862,7 @@ static input_plugin_t *v4l_class_get_radio_instance (input_class_t *cls_gen,
entry = this->stream->xine->config->lookup_entry(this->stream->xine->config,
"media.video4linux.radio_device");
- if((this->radio_fd = open_cloexec(entry->str_value, O_RDWR)) < 0) {
+ if((this->radio_fd = xine_open_cloexec(entry->str_value, O_RDWR)) < 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
"input_v4l: error opening v4l device (%s): %s\n",
entry->str_value, strerror(errno));
diff --git a/src/input/input_vcd.c b/src/input/input_vcd.c
index 35f76c042..14b86a4c0 100644
--- a/src/input/input_vcd.c
+++ b/src/input/input_vcd.c
@@ -832,7 +832,7 @@ static int vcd_plugin_open (input_plugin_t *this_gen) {
char *filename;
int fd;
- fd = open_cloexec(cls->device, O_RDONLY|O_EXCL);
+ fd = xine_open_cloexec(cls->device, O_RDONLY|O_EXCL);
if (fd == -1) {
return 0;
}
@@ -966,7 +966,7 @@ static xine_mrl_t **vcd_class_get_dir (input_class_t *this_gen, const char *file
return NULL;
- fd = open_cloexec(this->device, O_RDONLY|O_EXCL);
+ fd = xine_open_cloexec(this->device, O_RDONLY|O_EXCL);
if (fd == -1) {
xprintf (this->xine, XINE_VERBOSITY_LOG,
@@ -1028,7 +1028,7 @@ static char ** vcd_class_get_autoplay_list (input_class_t *this_gen, int *num_fi
int i, fd;
- fd = open_cloexec(this->device, O_RDONLY|O_EXCL);
+ fd = xine_open_cloexec(this->device, O_RDONLY|O_EXCL);
if (fd == -1) {
xprintf (this->xine, XINE_VERBOSITY_LOG,
diff --git a/src/input/media_helper.c b/src/input/media_helper.c
index 616793499..1a82a406c 100644
--- a/src/input/media_helper.c
+++ b/src/input/media_helper.c
@@ -99,7 +99,7 @@ int media_eject_media (xine_t *xine, const char *device)
media_umount_media(device);
/* printf("input_dvd: umount result: %s\n", strerror(errno)); */
- if ((fd = open_cloexec(device, O_RDONLY|O_NONBLOCK)) > -1) {
+ if ((fd = xine_open_cloexec(device, O_RDONLY|O_NONBLOCK)) > -1) {
#if defined (__linux__)
int ret, status;
diff --git a/src/libw32dll/wine/registry.c b/src/libw32dll/wine/registry.c
index 45e44625c..5f9a3fdc4 100644
--- a/src/libw32dll/wine/registry.c
+++ b/src/libw32dll/wine/registry.c
@@ -90,7 +90,7 @@ static void open_registry(void)
printf("Multiple open_registry(>\n");
return;
}
- fd = open_cloexec(localregpathname, O_RDONLY);
+ fd = xine_open_cloexec(localregpathname, O_RDONLY);
if (fd == -1)
{
printf("Creating new registry\n");
@@ -133,7 +133,7 @@ static void save_registry(void)
int fd, i;
if (!regs)
init_registry();
- fd = create_cloexec(localregpathname, O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
+ fd = xine_create_cloexec(localregpathname, O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd == -1)
{
printf("Failed to open registry file '%s' for writing.\n",
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);
diff --git a/src/video_out/video_out_fb.c b/src/video_out/video_out_fb.c
index da6dbd8ce..cfc5cf3a6 100644
--- a/src/video_out/video_out_fb.c
+++ b/src/video_out/video_out_fb.c
@@ -808,17 +808,17 @@ static int open_fb_device(config_values_t *config, xine_t *xine)
XINE_CONFIG_SECURITY, NULL, NULL);
if(strlen(device_name) > 3)
{
- fd = open_cloexec(device_name, O_RDWR);
+ fd = xine_open_cloexec(device_name, O_RDWR);
}
else
{
device_name = "/dev/fb1";
- fd = open_cloexec(device_name, O_RDWR);
+ fd = xine_open_cloexec(device_name, O_RDWR);
if(fd < 0)
{
device_name = "/dev/fb0";
- fd = open_cloexec(device_name, O_RDWR);
+ fd = xine_open_cloexec(device_name, O_RDWR);
}
}
diff --git a/src/video_out/video_out_pgx64.c b/src/video_out/video_out_pgx64.c
index e3d8b4746..7c82f6145 100644
--- a/src/video_out/video_out_pgx64.c
+++ b/src/video_out/video_out_pgx64.c
@@ -292,7 +292,7 @@ static int setup_dga(pgx64_driver_t *this)
devname = dga_draw_devname(this->dgadraw);
DGA_DRAW_UNLOCK(this->dgadraw);
- if ((this->devfd = open_cloexec(devname, O_RDWR)) < 0) {
+ if ((this->devfd = xine_open_cloexec(devname, O_RDWR)) < 0) {
xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("video_out_pgx64: Error: can't open framebuffer device '%s'\n"), devname);
XDgaUnGrabDrawable(this->dgadraw);
XUnlockDisplay(this->display);
diff --git a/src/video_out/video_out_vidix.c b/src/video_out/video_out_vidix.c
index 143d41234..41406fb58 100644
--- a/src/video_out/video_out_vidix.c
+++ b/src/video_out/video_out_vidix.c
@@ -1245,7 +1245,7 @@ static vo_driver_t *vidixfb_open_plugin (video_driver_class_t *class_gen, const
XINE_CONFIG_SECURITY, NULL, NULL);
/* Open fb device for reading */
- if((fd = open_cloexec("/dev/fb0", O_RDONLY)) < 0) {
+ if((fd = xine_open_cloexec("/dev/fb0", O_RDONLY)) < 0) {
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
"video_out_vidix: unable to open frame buffer device \"%s\": %s\n", device, strerror(errno));
return NULL;
diff --git a/src/xine-engine/io_helper.c b/src/xine-engine/io_helper.c
index 871b44517..399cb25a4 100644
--- a/src/xine-engine/io_helper.c
+++ b/src/xine-engine/io_helper.c
@@ -60,23 +60,13 @@ static int _x_io_tcp_connect_ipv4(xine_stream_t *stream, const char *host, int p
return -1;
}
- s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ s = xine_socket_cloexec(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) {
_x_message(stream, XINE_MSG_CONNECTION_REFUSED, "failed to create socket", strerror(errno), NULL);
return -1;
}
#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;
@@ -154,7 +144,7 @@ int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) {
while (tmpaddr) {
- s = socket(tmpaddr->ai_family, SOCK_STREAM, IPPROTO_TCP);
+ s = xine_socket_cloexec(tmpaddr->ai_family, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) {
_x_message(stream, XINE_MSG_CONNECTION_REFUSED,
"failed to create socket", strerror(errno), NULL);
@@ -162,16 +152,6 @@ 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.
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index 02a06aa24..61f2d71c5 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -35,10 +35,12 @@
#include <errno.h>
#include <pwd.h>
+#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
+#include <sys/socket.h>
#if HAVE_EXECINFO_H
#include <execinfo.h>
@@ -734,7 +736,7 @@ static int set_close_on_execute(int fd)
}
-int open_cloexec(const char *name, int flags)
+int xine_open_cloexec(const char *name, int flags)
{
int fd = open(name, (flags | O_CLOEXEC));
@@ -745,7 +747,7 @@ int open_cloexec(const char *name, int flags)
return fd;
}
-int create_cloexec(const char *name, int flags, mode_t mode)
+int xine_create_cloexec(const char *name, int flags, mode_t mode)
{
int fd = open(name, (flags | O_CREAT | O_CLOEXEC), mode);
@@ -756,3 +758,18 @@ int create_cloexec(const char *name, int flags, mode_t mode)
return fd;
}
+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
+ }
+
+ return s;
+}
+