From 62a669d9f04e83debe729347617a935707badc7e Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 1 Oct 2011 14:14:27 +0100 Subject: 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. --- src/audio_out/audio_file_out.c | 2 +- src/audio_out/audio_oss_out.c | 8 ++++---- src/audio_out/audio_sun_out.c | 8 ++++---- src/input/input_cdda.c | 2 +- src/input/input_dvb.c | 14 +++++++------- src/input/input_file.c | 2 +- src/input/input_net.c | 24 ++++++++++++++++++++++++ src/input/input_pvr.c | 10 +++++----- src/input/input_stdin_fifo.c | 2 +- src/input/input_v4l.c | 10 +++++----- src/input/input_vcd.c | 6 +++--- src/input/media_helper.c | 2 +- src/libw32dll/wine/registry.c | 4 ++-- src/video_out/video_out_fb.c | 6 +++--- src/video_out/video_out_pgx64.c | 2 +- src/video_out/video_out_syncfb.c | 4 ++-- src/video_out/video_out_vidix.c | 2 +- src/xine-engine/io_helper.c | 20 ++++++++++++++++++++ src/xine-utils/utils.c | 39 +++++++++++++++++++++++++++++++++++++++ src/xine-utils/xine_check.c | 6 +++--- src/xine-utils/xineutils.h | 12 ++++++++++++ 21 files changed, 140 insertions(+), 45 deletions(-) diff --git a/src/audio_out/audio_file_out.c b/src/audio_out/audio_file_out.c index 7b7bfe950..e39291f4e 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 = open(this->fname, O_WRONLY|O_TRUNC|O_CREAT, 0644); + this->fd = 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 bd16a6dd3..a7e320107 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(this->audio_dev,O_WRONLY|O_NONBLOCK); + this->audio_fd = 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(this->audio_dev, O_WRONLY|O_NONBLOCK); + audio_fd = 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(this->audio_dev, O_WRONLY|O_NONBLOCK); + audio_fd = open_cloexec(this->audio_dev, O_WRONLY|O_NONBLOCK); if(audio_fd < 0) { @@ -1051,7 +1051,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da _x_abort(); } - this->mixer.fd = open(this->mixer.name, O_RDONLY); + this->mixer.fd = 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 2a154c09d..552d521bb 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(dev, O_WRONLY|O_NONBLOCK)) < 0) + if ((fd = open_cloexec(dev, O_WRONLY|O_NONBLOCK)) < 0) goto error; /* We wanted non blocking open but now put it back to normal */ @@ -451,7 +451,7 @@ static int ao_sun_open(ao_driver_t *this_gen, * open audio device */ - this->audio_fd = open(this->audio_dev, O_WRONLY|O_NONBLOCK); + this->audio_fd = 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)); @@ -941,8 +941,8 @@ static ao_driver_t *ao_sun_open_plugin (audio_driver_class_t *class_gen, const v /* * open the device */ - - this->audio_fd = open(this->audio_dev = devname, O_WRONLY|O_NONBLOCK); + this->audio_dev = devname; + this->audio_fd = open_cloexec(devname, O_WRONLY|O_NONBLOCK); if(this->audio_fd < 0) { diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 567f38dd0..00c305ea1 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1951,7 +1951,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 (cdda_device, O_RDONLY | O_NONBLOCK); + fd = 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 e6abfd3d5..e56c3d260 100644 --- a/src/input/input_dvb.c +++ b/src/input/input_dvb.c @@ -606,7 +606,7 @@ static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter) snprintf(this->dvr_device,100,"/dev/dvb/adapter%i/dvr0",this->adapter_num); snprintf(video_device,100,"/dev/dvb/adapter%i/video0",this->adapter_num); - if ((this->fd_frontend = open(this->frontend_device, O_RDWR)) < 0) { + if ((this->fd_frontend = open_cloexec(this->frontend_device, O_RDWR)) < 0) { xprintf(this->xine, XINE_VERBOSITY_DEBUG, "FRONTEND DEVICE: %s\n", strerror(errno)); tuner_dispose(this); return NULL; @@ -619,7 +619,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(this->demux_device, O_RDWR); + this->fd_pidfilter[x] = 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); @@ -627,7 +627,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(this->demux_device, O_RDWR); + this->fd_subfilter[x] = 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)); } @@ -2140,7 +2140,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(this->tuner->demux_device, O_RDWR); + this->tuner->fd_pidfilter[x] = open_cloexec(this->tuner->demux_device, O_RDWR); } if (!tuner_set_channel (this, &this->channels[channel])) { @@ -2174,7 +2174,7 @@ static int switch_channel(dvb_input_plugin_t *this, int channel) { this->channel = channel; - this->fd = open (this->tuner->dvr_device, O_RDONLY | O_NONBLOCK); + this->fd = open_cloexec(this->tuner->dvr_device, O_RDONLY | O_NONBLOCK); this->tuned_in = 1; pthread_mutex_unlock (&this->channel_change_mutex); @@ -2248,7 +2248,7 @@ static void do_record (dvb_input_plugin_t *this) { } /* start recording */ - this->record_fd = open (filename, O_CREAT | O_APPEND | O_WRONLY, 0644); + this->record_fd = create_cloexec(filename, O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); this->stream->osd_renderer->clear (this->rec_osd); @@ -2992,7 +2992,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen) return 0; } - if ((this->fd = open(this->tuner->dvr_device, O_RDONLY |O_NONBLOCK)) < 0) { + if ((this->fd = 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 4a1937390..b8d2b12b7 100644 --- a/src/input/input_file.c +++ b/src/input/input_file.c @@ -362,7 +362,7 @@ static int file_plugin_open (input_plugin_t *this_gen ) { else filename = strdup(this->mrl); /* NEVER unescape plain file names! */ - this->fh = open (filename, O_RDONLY|O_BINARY); + this->fh = 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 55339b2bb..076c11634 100644 --- a/src/input/input_net.c +++ b/src/input/input_net.c @@ -122,6 +122,18 @@ static int host_connect_attempt_ipv4(struct in_addr ia, int port, xine_t *xine) 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); @@ -152,6 +164,18 @@ static int host_connect_attempt(int family, struct sockaddr* sin, int addrlen, x 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 diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c index 5e7f7bca9..7ccad806e 100644 --- a/src/input/input_pvr.c +++ b/src/input/input_pvr.c @@ -583,7 +583,7 @@ static int pvr_break_rec_page (pvr_input_plugin_t *this) { lprintf("opening pvr file for writing (%s)\n", filename); - this->rec_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666 ); + this->rec_fd = 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); @@ -740,7 +740,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(filename, O_RDONLY ); + this->play_fd = 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); @@ -1008,7 +1008,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 (this->class->devname, O_RDWR); + this->dev_fd = 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 ); @@ -1155,7 +1155,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 (this->class->devname, O_RDWR); + this->dev_fd = 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 ); @@ -1415,7 +1415,7 @@ static int pvr_plugin_open (input_plugin_t *this_gen ) { this->saved_id = 0; - this->dev_fd = open (this->class->devname, O_RDWR); + this->dev_fd = 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 74f2a1014..c73488722 100644 --- a/src/input/input_stdin_fifo.c +++ b/src/input/input_stdin_fifo.c @@ -253,7 +253,7 @@ static int stdin_plugin_open (input_plugin_t *this_gen ) { char *filename; filename = (char *) &this->mrl[5]; - this->fh = open (filename, FILE_FLAGS); + this->fh = 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 e3af41f85..68ed44b9c 100644 --- a/src/input/input_v4l.c +++ b/src/input/input_v4l.c @@ -797,7 +797,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(entry->str_value, O_RDWR)) < 0) { + if((this->radio_fd = 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)); @@ -850,7 +850,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(entry->str_value, O_RDWR)) < 0) { + if((this->video_fd = 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)); @@ -1539,7 +1539,7 @@ static void v4l_plugin_dispose (input_plugin_t *this_gen) { if (this->tuner_name) free(this->tuner_name); - /* Close video device only if device was openend */ + /* Close video device only if device was opened */ if (this->video_fd > 0) { /* Restore v4l audio volume */ @@ -1770,7 +1770,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(entry->str_value, O_RDWR)) < 0) { + if((this->video_fd = 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)); @@ -1833,7 +1833,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(entry->str_value, O_RDWR)) < 0) { + if((this->radio_fd = 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 7000778b7..1da5b2839 100644 --- a/src/input/input_vcd.c +++ b/src/input/input_vcd.c @@ -829,7 +829,7 @@ static int vcd_plugin_open (input_plugin_t *this_gen) { char *filename; int fd; - fd = open (cls->device, O_RDONLY|O_EXCL); + fd = open_cloexec(cls->device, O_RDONLY|O_EXCL); if (fd == -1) { return 0; } @@ -972,7 +972,7 @@ static xine_mrl_t **vcd_class_get_dir (input_class_t *this_gen, const char *file return NULL; - fd = open (this->device, O_RDONLY|O_EXCL); + fd = open_cloexec(this->device, O_RDONLY|O_EXCL); if (fd == -1) { xprintf (this->xine, XINE_VERBOSITY_LOG, @@ -1034,7 +1034,7 @@ static char ** vcd_class_get_autoplay_list (input_class_t *this_gen, int *num_fi int i, fd; - fd = open (this->device, O_RDONLY|O_EXCL); + fd = 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 e19ca63e6..616793499 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 (device, O_RDONLY|O_NONBLOCK)) > -1) { + if ((fd = 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 0ccf3de9b..6b9a30fa3 100644 --- a/src/libw32dll/wine/registry.c +++ b/src/libw32dll/wine/registry.c @@ -89,7 +89,7 @@ static void open_registry(void) printf("Multiple open_registry(>\n"); return; } - fd = open(localregpathname, O_RDONLY); + fd = open_cloexec(localregpathname, O_RDONLY); if (fd == -1) { printf("Creating new registry\n"); @@ -132,7 +132,7 @@ static void save_registry(void) int fd, i; if (!regs) init_registry(); - fd = open(localregpathname, O_WRONLY | O_CREAT, 00666); + fd = 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/video_out/video_out_fb.c b/src/video_out/video_out_fb.c index 315e77e66..752a18a27 100644 --- a/src/video_out/video_out_fb.c +++ b/src/video_out/video_out_fb.c @@ -825,17 +825,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(device_name, O_RDWR); + fd = open_cloexec(device_name, O_RDWR); } else { device_name = "/dev/fb1"; - fd = open(device_name, O_RDWR); + fd = open_cloexec(device_name, O_RDWR); if(fd < 0) { device_name = "/dev/fb0"; - fd = open(device_name, O_RDWR); + fd = 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 c9ec38aa8..8f46e2dde 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(devname, O_RDWR)) < 0) { + if ((this->devfd = 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_syncfb.c b/src/video_out/video_out_syncfb.c index b3385a943..ac79f7740 100644 --- a/src/video_out/video_out_syncfb.c +++ b/src/video_out/video_out_syncfb.c @@ -888,7 +888,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi _x_alphablend_init(&this->alphablend_extra_data, class->xine); /* check for syncfb device */ - if((this->fd = open(class->device_name, O_RDWR)) < 0) { + if((this->fd = open_cloexec(class->device_name, O_RDWR)) < 0) { xprintf(class->xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: aborting. (unable to open syncfb device \"%s\")\n", class->device_name); free(this); @@ -1095,7 +1095,7 @@ static void *init_class (xine_t *xine, void *visual_gen) { XINE_CONFIG_SECURITY, NULL, NULL); /* check for syncfb device */ - if((fd = open(device_name, O_RDWR)) < 0) { + if((fd = open_cloexec(device_name, O_RDWR)) < 0) { xprintf(xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: aborting. (unable to open syncfb device \"%s\")\n", device_name); return NULL; diff --git a/src/video_out/video_out_vidix.c b/src/video_out/video_out_vidix.c index 8298d3ede..b70844312 100644 --- a/src/video_out/video_out_vidix.c +++ b/src/video_out/video_out_vidix.c @@ -1257,7 +1257,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("/dev/fb0", O_RDONLY)) < 0) { + if((fd = 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 b06c47709..5bcd95c63 100644 --- a/src/xine-engine/io_helper.c +++ b/src/xine-engine/io_helper.c @@ -66,6 +66,16 @@ static int _x_io_tcp_connect_ipv4(xine_stream_t *stream, const char *host, int p 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); @@ -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. diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 2f62c95a8..f5d5a0ff3 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -38,6 +38,7 @@ #include #include #include +#include #if HAVE_EXECINFO_H #include @@ -56,6 +57,10 @@ #include #endif +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + typedef struct { char *language; /* name of the locale */ char *encoding; /* typical encoding */ @@ -697,3 +702,37 @@ char *xine_strcat_realloc (char **dest, char *append) strcat (*dest = newstr, append); return newstr; } + + +static int set_close_on_execute(int fd) +{ +#ifndef WIN32 + return fcntl(fd, F_SETFD, FD_CLOEXEC); +#else + return SetHandleInformation((HANDLE)_get_osfhandle(fd), HANDLE_FLAG_INHERIT, 0); +#endif +} + + +int open_cloexec(const char *name, int flags) +{ + int fd = open(name, (flags | O_CLOEXEC)); + + if (fd >= 0) { + set_close_on_execute(fd); + } + + return fd; +} + +int 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); + } + + return fd; +} + diff --git a/src/xine-utils/xine_check.c b/src/xine-utils/xine_check.c index ad94b0382..90100d725 100644 --- a/src/xine-utils/xine_check.c +++ b/src/xine-utils/xine_check.c @@ -168,7 +168,7 @@ static xine_health_check_t* _x_health_check_cdrom (xine_health_check_t* hc) { return hc; } - if ( (fd = open(hc->cdrom_dev, O_RDWR)) < 0) { + if ( (fd = open(hc->cdrom_dev, O_RDWR | O_CLOEXEC)) < 0) { switch (errno) { case EACCES: set_hc_result (hc, XINE_HEALTH_CHECK_FAIL, "FAILED - %s permissions are not sufficient\n.", hc->cdrom_dev); @@ -204,7 +204,7 @@ static xine_health_check_t* _x_health_check_dvdrom(xine_health_check_t* hc) { return hc; } - if ( (fd = open(hc->dvd_dev, O_RDWR)) < 0) { + if ( (fd = open(hc->dvd_dev, O_RDWR | O_CLOEXEC)) < 0) { switch (errno) { case EACCES: set_hc_result (hc, XINE_HEALTH_CHECK_FAIL, "FAILED - %s permissions are not sufficient\n.", hc->dvd_dev); @@ -247,7 +247,7 @@ static xine_health_check_t* _x_health_check_dma (xine_health_check_t* hc) { return hc; } - fd = open (hc->dvd_dev, O_RDONLY | O_NONBLOCK); + fd = open (hc->dvd_dev, O_RDONLY | O_NONBLOCK | O_CLOEXEC); if (fd < 0) { set_hc_result(hc, XINE_HEALTH_CHECK_FAIL, "FAILED - Could not open %s.\n", hc->dvd_dev); return hc; diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 0fd0bbf0e..5fe1fb7e5 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -215,6 +215,18 @@ void xine_strdupa(char *dest, char *src) XINE_PROTECTED XINE_DEPRECATED; */ char *xine_strcat_realloc (char **dest, char *append) XINE_PROTECTED; +/** + * opens a file, ensuring that the descriptor will be closed + * automatically after a fork/execute. + */ +int open_cloexec(const char *name, int flags) XINE_PROTECTED; + +/** + * creates a file, ensuring that the descriptor will be closed + * automatically after a fork/execute. + */ +int create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED; + /* * Color Conversion Utility Functions * The following data structures and functions facilitate the conversion -- cgit v1.2.3 From 81c4665ec233961b07544445b3e21b99fe11c734 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 1 Oct 2011 21:38:25 +0100 Subject: Add CLOEXEC flag to DXR3 plugin's descriptors. --- src/dxr3/dxr3_decode_spu.c | 2 +- src/dxr3/dxr3_decode_video.c | 4 ++-- src/dxr3/dxr3_scr.c | 2 +- src/dxr3/video_out_dxr3.c | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dxr3/dxr3_decode_spu.c b/src/dxr3/dxr3_decode_spu.c index 683666d21..8789ffa11 100644 --- a/src/dxr3/dxr3_decode_spu.c +++ b/src/dxr3/dxr3_decode_spu.c @@ -257,7 +257,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(tmpstr, O_WRONLY)) < 0) { + if ((this->fd_spu = 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 132998a72..101098af3 100644 --- a/src/dxr3/dxr3_decode_video.c +++ b/src/dxr3/dxr3_decode_video.c @@ -249,7 +249,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(tmpstr, O_WRONLY)) < 0) { + if ((this->fd_control = 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); @@ -546,7 +546,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(tmpstr, O_WRONLY)) < 0) { + if ((this->fd_video = 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 dd0ea5840..ad6d98b50 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(tmpstr, O_WRONLY)) < 0) { + if ((this->fd_control = 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 f4121f59c..bc89e901d 100644 --- a/src/dxr3/video_out_dxr3.c +++ b/src/dxr3/video_out_dxr3.c @@ -276,7 +276,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(tmpstr, O_WRONLY)) < 0) { + if ((this->fd_control = 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)); @@ -285,7 +285,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 (tmpstr, O_WRONLY | O_SYNC )) < 0) { + if ((this->fd_video = 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; @@ -658,7 +658,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(tmpstr, O_WRONLY)) < 0) + if ((this->fd_video = 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)); @@ -857,7 +857,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 (tmpstr, O_WRONLY)) < 0) { + if ((this->fd_spu = 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)); -- cgit v1.2.3 From b01bd8b294c35be664b018dd6e5fa9ec30e521ca Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 01:13:10 +0100 Subject: Assign O_CLOEXEC a safe default value if it hasn't been defined already. --- src/xine-utils/xine_check.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/xine-utils/xine_check.c b/src/xine-utils/xine_check.c index 90100d725..5bc936da8 100644 --- a/src/xine-utils/xine_check.c +++ b/src/xine-utils/xine_check.c @@ -46,6 +46,10 @@ #include "xineutils.h" +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + #if defined(__linux__) #include -- cgit v1.2.3 From 5ec743f4ddf302d10b3547cfc18ae0ca8aed1edd Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 01:58:22 +0100 Subject: Add CLOEXEC to another descriptor. (Merge from 1.2 branch). --- src/input/input_dvb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c index e56c3d260..cae56d301 100644 --- a/src/input/input_dvb.c +++ b/src/input/input_dvb.c @@ -648,7 +648,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(video_device, O_RDWR)) < 0) { + if ((test_video=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"); -- cgit v1.2.3 From 5db268a002e7a102855e84a3ff5e1c27ca7cb927 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 12:11:56 +0100 Subject: Prefix open_cloexec() and create_cloexec() with xine_, and add new xine_socket_cloexec() function. --- src/audio_out/audio_file_out.c | 2 +- src/audio_out/audio_oss_out.c | 8 ++++---- src/audio_out/audio_sun_out.c | 6 +++--- src/dxr3/dxr3_decode_spu.c | 2 +- src/dxr3/dxr3_decode_video.c | 4 ++-- src/dxr3/dxr3_scr.c | 2 +- src/dxr3/video_out_dxr3.c | 8 ++++---- src/input/input_cdda.c | 2 +- src/input/input_dvb.c | 16 ++++++++-------- src/input/input_file.c | 2 +- src/input/input_net.c | 31 +++---------------------------- src/input/input_pvr.c | 10 +++++----- src/input/input_stdin_fifo.c | 6 +++--- src/input/input_v4l.c | 8 ++++---- src/input/input_vcd.c | 6 +++--- src/input/media_helper.c | 2 +- src/libw32dll/wine/registry.c | 4 ++-- src/video_out/video_out_fb.c | 6 +++--- src/video_out/video_out_pgx64.c | 2 +- src/video_out/video_out_syncfb.c | 4 ++-- src/video_out/video_out_vidix.c | 2 +- src/xine-engine/io_helper.c | 24 ++---------------------- src/xine-utils/utils.c | 21 +++++++++++++++++++-- src/xine-utils/xineutils.h | 10 ++++++++-- 24 files changed, 83 insertions(+), 105 deletions(-) diff --git a/src/audio_out/audio_file_out.c b/src/audio_out/audio_file_out.c index e39291f4e..0895a2eac 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 a7e320107..ca6a91546 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) { @@ -1051,7 +1051,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da _x_abort(); } - 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 552d521bb..cd6319ee8 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 */ @@ -451,7 +451,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)); @@ -942,7 +942,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 8789ffa11..100ba7674 100644 --- a/src/dxr3/dxr3_decode_spu.c +++ b/src/dxr3/dxr3_decode_spu.c @@ -257,7 +257,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 101098af3..71c6b4d1b 100644 --- a/src/dxr3/dxr3_decode_video.c +++ b/src/dxr3/dxr3_decode_video.c @@ -249,7 +249,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); @@ -546,7 +546,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 bc89e901d..5718c0687 100644 --- a/src/dxr3/video_out_dxr3.c +++ b/src/dxr3/video_out_dxr3.c @@ -276,7 +276,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)); @@ -285,7 +285,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; @@ -658,7 +658,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)); @@ -857,7 +857,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 00c305ea1..052a1b257 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1951,7 +1951,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 cae56d301..fc6e2b7c4 100644 --- a/src/input/input_dvb.c +++ b/src/input/input_dvb.c @@ -606,7 +606,7 @@ static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter) snprintf(this->dvr_device,100,"/dev/dvb/adapter%i/dvr0",this->adapter_num); snprintf(video_device,100,"/dev/dvb/adapter%i/video0",this->adapter_num); - if ((this->fd_frontend = open_cloexec(this->frontend_device, O_RDWR)) < 0) { + if ((this->fd_frontend = xine_open_cloexec(this->frontend_device, O_RDWR)) < 0) { xprintf(this->xine, XINE_VERBOSITY_DEBUG, "FRONTEND DEVICE: %s\n", strerror(errno)); tuner_dispose(this); return NULL; @@ -619,7 +619,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); @@ -627,7 +627,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)); } @@ -648,7 +648,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"); @@ -2140,7 +2140,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])) { @@ -2174,7 +2174,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); @@ -2248,7 +2248,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); @@ -2992,7 +2992,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 b8d2b12b7..d5313d4dc 100644 --- a/src/input/input_file.c +++ b/src/input/input_file.c @@ -362,7 +362,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 076c11634..5c927a6d5 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,27 +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; + int s = xine_socket_cloexec(family, SOCK_STREAM, IPPROTO_TCP); - s = socket(family, SOCK_STREAM, IPPROTO_TCP); - if (s==-1) { + 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 diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c index 7ccad806e..875fb84b0 100644 --- a/src/input/input_pvr.c +++ b/src/input/input_pvr.c @@ -583,7 +583,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); @@ -740,7 +740,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); @@ -1008,7 +1008,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 ); @@ -1155,7 +1155,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 ); @@ -1415,7 +1415,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 c73488722..d3a2e83e1 100644 --- a/src/input/input_stdin_fifo.c +++ b/src/input/input_stdin_fifo.c @@ -250,10 +250,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 68ed44b9c..b88c4821d 100644 --- a/src/input/input_v4l.c +++ b/src/input/input_v4l.c @@ -797,7 +797,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)); @@ -850,7 +850,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)); @@ -1770,7 +1770,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)); @@ -1833,7 +1833,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 1da5b2839..20bf8c845 100644 --- a/src/input/input_vcd.c +++ b/src/input/input_vcd.c @@ -829,7 +829,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; } @@ -972,7 +972,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, @@ -1034,7 +1034,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 6b9a30fa3..7c4c0f5d8 100644 --- a/src/libw32dll/wine/registry.c +++ b/src/libw32dll/wine/registry.c @@ -89,7 +89,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"); @@ -132,7 +132,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/video_out/video_out_fb.c b/src/video_out/video_out_fb.c index 752a18a27..c8697694e 100644 --- a/src/video_out/video_out_fb.c +++ b/src/video_out/video_out_fb.c @@ -825,17 +825,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 8f46e2dde..29d51194e 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_syncfb.c b/src/video_out/video_out_syncfb.c index ac79f7740..4cb11dc93 100644 --- a/src/video_out/video_out_syncfb.c +++ b/src/video_out/video_out_syncfb.c @@ -888,7 +888,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi _x_alphablend_init(&this->alphablend_extra_data, class->xine); /* check for syncfb device */ - if((this->fd = open_cloexec(class->device_name, O_RDWR)) < 0) { + if((this->fd = xine_open_cloexec(class->device_name, O_RDWR)) < 0) { xprintf(class->xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: aborting. (unable to open syncfb device \"%s\")\n", class->device_name); free(this); @@ -1095,7 +1095,7 @@ static void *init_class (xine_t *xine, void *visual_gen) { XINE_CONFIG_SECURITY, NULL, NULL); /* check for syncfb device */ - if((fd = open_cloexec(device_name, O_RDWR)) < 0) { + if((fd = xine_open_cloexec(device_name, O_RDWR)) < 0) { xprintf(xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: aborting. (unable to open syncfb device \"%s\")\n", device_name); return NULL; diff --git a/src/video_out/video_out_vidix.c b/src/video_out/video_out_vidix.c index b70844312..0a7f6a8f6 100644 --- a/src/video_out/video_out_vidix.c +++ b/src/video_out/video_out_vidix.c @@ -1257,7 +1257,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 5bcd95c63..22f34ffc2 100644 --- a/src/xine-engine/io_helper.c +++ b/src/xine-engine/io_helper.c @@ -60,22 +60,12 @@ 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); @@ -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 f5d5a0ff3..25e8cc2b0 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -35,7 +35,9 @@ #include #include +#include #include +#include #include #include #include @@ -714,7 +716,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)); @@ -725,7 +727,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); @@ -736,3 +738,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; +} + diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 5fe1fb7e5..d0946e471 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -219,13 +219,19 @@ char *xine_strcat_realloc (char **dest, char *append) XINE_PROTECTED; * opens a file, ensuring that the descriptor will be closed * automatically after a fork/execute. */ -int open_cloexec(const char *name, int flags) XINE_PROTECTED; +int xine_open_cloexec(const char *name, int flags) XINE_PROTECTED; /** * creates a file, ensuring that the descriptor will be closed * automatically after a fork/execute. */ -int create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED; +int xine_create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED; + +/** + * creates a socket, ensuring that the descriptor will be closed + * automatically after a fork/execute. + */ +int xine_socket_cloexec(int domain, int type, int protocol) XINE_PROTECTED; /* * Color Conversion Utility Functions -- cgit v1.2.3 From fa660f82ae5889b931c645133abb151f26fba343 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 21:07:39 +0100 Subject: 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 have been assigned "internal" visibility so that they can be used throughout libxine.so itself while still not being exported to the global symbol table. In other words, they're both as close to being "static" as I can make them. --- configure.ac | 4 ++++ src/input/input_rtp.c | 4 ++-- src/xine-engine/Makefile.am | 2 +- src/xine-engine/broadcaster.c | 4 +++- src/xine-engine/xine_internal.h | 1 + src/xine-engine/xine_private.h | 39 +++++++++++++++++++++++++++++++++++++++ src/xine-utils/attributes.h | 9 +++++++++ src/xine-utils/utils.c | 21 +++++++++++++-------- 8 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/xine-engine/xine_private.h diff --git a/configure.ac b/configure.ac index ffadce496..c449de3c8 100644 --- a/configure.ac +++ b/configure.ac @@ -2299,6 +2299,10 @@ CC_ATTRIBUTE_VISIBILITY([protected], [visibility_export="protected"], [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])] ) +CC_ATTRIBUTE_VISIBILITY([internal], [visibility_export="internal"], + [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])] +) + if test "x$visibility_export" != "x"; then CC_FLAG_VISIBILITY([ AC_DEFINE([EXPORTED], [__attribute__((visibility("default")))], diff --git a/src/input/input_rtp.c b/src/input/input_rtp.c index e91e43f55..a7102fccd 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/Makefile.am b/src/xine-engine/Makefile.am index 576c61b14..67ae63fae 100644 --- a/src/xine-engine/Makefile.am +++ b/src/xine-engine/Makefile.am @@ -41,7 +41,7 @@ xineinclude_HEADERS = buffer.h metronom.h configfile.h vo_scale.h \ plugin_catalog.h audio_decoder.h video_decoder.h post.h \ io_helper.h broadcaster.h info_helper.h refcounter.h alphablend.h -noinst_HEADERS = bswap.h ffmpeg_bswap.h +noinst_HEADERS = bswap.h ffmpeg_bswap.h xine_private.h if WIN32 install-exec-local: diff --git a/src/xine-engine/broadcaster.c b/src/xine-engine/broadcaster.c index a554337a3..3f943171f 100644 --- a/src/xine-engine/broadcaster.c +++ b/src/xine-engine/broadcaster.c @@ -227,6 +227,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)); @@ -307,7 +309,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_internal.h b/src/xine-engine/xine_internal.h index 7566c83e0..bb2113831 100644 --- a/src/xine-engine/xine_internal.h +++ b/src/xine-engine/xine_internal.h @@ -48,6 +48,7 @@ extern "C" { # include "io_helper.h" # include "info_helper.h" # include "alphablend.h" +# include "xine_private.h" #else # include # include diff --git a/src/xine-engine/xine_private.h b/src/xine-engine/xine_private.h new file mode 100644 index 000000000..1f3564cbc --- /dev/null +++ b/src/xine-engine/xine_private.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2000-2011 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + */ + +#ifndef HAVE_XINE_PRIVATE_H +#define HAVE_XINE_PRIVATE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * make file descriptors and sockets uninheritable + */ +int _x_set_file_close_on_exec(int fd) XINE_INTERNAL; + +int _x_set_socket_close_on_exec(int s) XINE_INTERNAL; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h index 2326dab18..9f02d9b7b 100644 --- a/src/xine-utils/attributes.h +++ b/src/xine-utils/attributes.h @@ -66,6 +66,15 @@ # define XINE_PROTECTED #endif +/* Export hidden only for private/internal libxine functions */ +#if defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_INTERNAL) +# define XINE_INTERNAL __attribute__((__visibility__("internal"))) +#elif defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT) +# define XINE_INTERNAL __attribute__((__visibility__("default"))) +#else +# define XINE_INTERNAL +#endif + #ifdef SUPPORT_ATTRIBUTE_SENTINEL # define XINE_SENTINEL __attribute__((__sentinel__)) #else diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 25e8cc2b0..70c600b96 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -706,7 +706,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); @@ -715,13 +715,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; @@ -732,7 +741,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; @@ -743,11 +752,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; -- cgit v1.2.3 From 415ae49518a9df44e1e872c225d9b89a5e94c515 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 3 Oct 2011 21:45:29 +0100 Subject: Simplify test for "internal" visibility compiler flag. --- configure.ac | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index c449de3c8..de54c62a2 100644 --- a/configure.ac +++ b/configure.ac @@ -2298,10 +2298,7 @@ CC_ATTRIBUTE_ALIGNED CC_ATTRIBUTE_VISIBILITY([protected], [visibility_export="protected"], [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])] ) - -CC_ATTRIBUTE_VISIBILITY([internal], [visibility_export="internal"], - [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])] -) +CC_ATTRIBUTE_VISIBILITY([internal]) if test "x$visibility_export" != "x"; then CC_FLAG_VISIBILITY([ -- cgit v1.2.3 From 7e335173083e1fc91f27927a2d749f5a09773b32 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 29 Sep 2011 06:18:00 +0200 Subject: Enable missing FFmpeg codecs for RV30 / RV40 and VP8 --HG-- extra : rebase_source : dd06e80a4a10ee355d073e77044440a1c09dc76e --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index de54c62a2..1f77c6d31 100644 --- a/configure.ac +++ b/configure.ac @@ -412,7 +412,7 @@ for ucname in $ffmpeg_uncommon_codecs; do done dnl popular ffmpeg codecs -ffmpeg_popular_codecs="CINEPAK FLASHSV H261 H263 H263I H264 INDEO2 INDEO3 MJPEG MJPEGB MPEG1VIDEO MPEG2VIDEO MPEG4 MPEGVIDEO MSMPEG4V1 MSMPEG4V2 MSMPEG4V3 MSRLE MSVIDEO1 QTRLE RV10 RV20 SVQ1 SVQ3 VC1 VP3 VP5 VP6 VP6F WMV1 WMV2 WMV3 COOK DTS EAC3 AAC_LATM FLAC MP2 MP3 QDM2 RA_144 RA_288 WAVPACK WMAV1 WMAV2 WMAPRO ADPCM_SWF" +ffmpeg_popular_codecs="CINEPAK FLASHSV H261 H263 H263I H264 INDEO2 INDEO3 MJPEG MJPEGB MPEG1VIDEO MPEG2VIDEO MPEG4 MPEGVIDEO MSMPEG4V1 MSMPEG4V2 MSMPEG4V3 MSRLE MSVIDEO1 QTRLE RV10 RV20 RV30 RV40 SVQ1 SVQ3 VC1 VP3 VP5 VP6 VP6F VP8 WMV1 WMV2 WMV3 COOK DTS EAC3 AAC_LATM FLAC MP2 MP3 QDM2 RA_144 RA_288 WAVPACK WMAV1 WMAV2 WMAPRO ADPCM_SWF" for ucname in $ffmpeg_popular_codecs; do config_name="CONFIG_${ucname}_DECODER" -- cgit v1.2.3