From: Andreas Ă–man Date: Thu, 26 Nov 2009 19:35:08 +0000 (+0000) Subject: Open all files with O_CLOEXEC X-Git-Tag: 2.12~401 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd353b28544a1699a0f4f5e0528d2215bbcb3d7e;p=thirdparty%2Ftvheadend.git Open all files with O_CLOEXEC --- diff --git a/Makefile b/Makefile index 41f9b44a7..99265fb24 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ LDFLAGS += -lrt # Core # SRCS = src/main.c \ + src/wrappers.c \ src/version.c \ src/access.c \ src/dtable.c \ diff --git a/docs/html/overview.html b/docs/html/overview.html index 9128947b7..fb2197d7b 100644 --- a/docs/html/overview.html +++ b/docs/html/overview.html @@ -9,7 +9,7 @@ Tvheadend is part of the HTS project hosted at -%%_SITEROOT_%% +http://www.lonelycoder.com/hts

It functions primarily as a TV streaming backend for the Showtime Mediaplayer but can be used standalone for other purposes, such as a Digital Video Recorder. diff --git a/src/dvb/dvb_adapter.c b/src/dvb/dvb_adapter.c index 52f2b876c..25387d7d2 100644 --- a/src/dvb/dvb_adapter.c +++ b/src/dvb/dvb_adapter.c @@ -182,7 +182,7 @@ tda_add(const char *path) snprintf(fname, sizeof(fname), "%s/frontend0", path); - fe = open(fname, O_RDWR | O_NONBLOCK); + fe = tvh_open(fname, O_RDWR | O_NONBLOCK, 0); if(fe == -1) { if(errno != ENOENT) tvhlog(LOG_ALERT, "dvb", @@ -434,7 +434,7 @@ dvb_adapter_input_dvr(void *aux) uint8_t tsb[188 * 10]; th_transport_t *t; - fd = open(tda->tda_dvr_path, O_RDONLY); + fd = tvh_open(tda->tda_dvr_path, O_RDONLY, 0); if(fd == -1) { tvhlog(LOG_ALERT, "dvb", "%s: unable to open dvr", tda->tda_dvr_path); return NULL; diff --git a/src/dvb/dvb_tables.c b/src/dvb/dvb_tables.c index 579814f14..07bf0fbff 100644 --- a/src/dvb/dvb_tables.c +++ b/src/dvb/dvb_tables.c @@ -143,7 +143,7 @@ tdt_open_fd(th_dvb_mux_instance_t *tdmi, th_dvb_table_t *tdt) assert(tdt->tdt_fd == -1); TAILQ_REMOVE(&tdmi->tdmi_table_queue, tdt, tdt_pending_link); - tdt->tdt_fd = open(tda->tda_demux_path, O_RDWR); + tdt->tdt_fd = tvh_open(tda->tda_demux_path, O_RDWR, 0); if(tdt->tdt_fd != -1) { diff --git a/src/dvb/dvb_transport.c b/src/dvb/dvb_transport.c index 0865b1f86..ecd1c6d25 100644 --- a/src/dvb/dvb_transport.c +++ b/src/dvb/dvb_transport.c @@ -59,7 +59,7 @@ dvb_transport_open_demuxers(th_dvb_adapter_t *tda, th_transport_t *t) if(st->st_demuxer_fd != -1) continue; - fd = open(tda->tda_demux_path, O_RDWR); + fd = tvh_open(tda->tda_demux_path, O_RDWR, 0); st->st_cc_valid = 0; if(fd == -1) { diff --git a/src/htsp.c b/src/htsp.c index 3e0ccb6e3..f73f810fa 100644 --- a/src/htsp.c +++ b/src/htsp.c @@ -707,7 +707,7 @@ htsp_generate_challenge(htsp_connection_t *htsp) { int fd, n; - if((fd = open("/dev/urandom", O_RDONLY)) < 0) + if((fd = tvh_open("/dev/urandom", O_RDONLY, 0)) < 0) return -1; n = read(fd, &htsp->htsp_challenge, 32); diff --git a/src/rawtsinput.c b/src/rawtsinput.c index 5ced1b2c1..d36cac695 100644 --- a/src/rawtsinput.c +++ b/src/rawtsinput.c @@ -286,7 +286,7 @@ rawts_init(const char *filename) { pthread_t ptid; rawts_t *rt; - int fd = open(filename, O_RDONLY); + int fd = tvh_open(filename, O_RDONLY, 0); if(fd == -1) { fprintf(stderr, "Unable to open %s -- %s\n", filename, strerror(errno)); diff --git a/src/rtsp.c b/src/rtsp.c index c5920cb5b..82d1d110d 100644 --- a/src/rtsp.c +++ b/src/rtsp.c @@ -306,7 +306,7 @@ genrand32(uint8_t *r) { int fd, n; - if((fd = open("/dev/urandom", O_RDONLY)) < 0) + if((fd = tvh_open("/dev/urandom", O_RDONLY, 0)) < 0) return -1; n = read(fd, r, 32); diff --git a/src/settings.c b/src/settings.c index f1ca19cab..0ebd7404d 100644 --- a/src/settings.c +++ b/src/settings.c @@ -120,7 +120,7 @@ hts_settings_save(htsmsg_t *record, const char *pathfmt, ...) snprintf(fullpath, sizeof(fullpath), "%s/%s.tmp", settingspath, path); - if((fd = open(fullpath, O_CREAT | O_TRUNC | O_RDWR, 0700)) < 0) { + if((fd = tvh_open(fullpath, O_CREAT | O_TRUNC | O_RDWR, 0700)) < 0) { tvhlog(LOG_ALERT, "settings", "Unable to create \"%s\" - %s", fullpath, strerror(errno)); return; @@ -167,7 +167,7 @@ hts_settings_load_one(const char *filename) if(stat(filename, &st) < 0) return NULL; - if((fd = open(filename, O_RDONLY)) < 0) + if((fd = tvh_open(filename, O_RDONLY, 0)) < 0) return NULL; mem = malloc(st.st_size + 1); diff --git a/src/tvhead.h b/src/tvhead.h index 054af3140..ca769da53 100644 --- a/src/tvhead.h +++ b/src/tvhead.h @@ -724,4 +724,6 @@ extern void scopedunlock(pthread_mutex_t **mtxp); #define tvh_strlcatf(buf, size, fmt...) \ snprintf((buf) + strlen(buf), (size) - strlen(buf), fmt) +int tvh_open(const char *pathname, int flags, mode_t mode); + #endif /* TV_HEAD_H */ diff --git a/src/v4l.c b/src/v4l.c index 876bbd7f6..041c68d28 100644 --- a/src/v4l.c +++ b/src/v4l.c @@ -177,7 +177,7 @@ v4l_transport_start(th_transport_t *t, unsigned int weight, int status, if(va->va_current_transport != NULL) return 1; // Adapter busy - fd = open(va->va_path, O_RDWR | O_NONBLOCK); + fd = tvh_open(va->va_path, O_RDWR | O_NONBLOCK, 0); if(fd == -1) { tvhlog(LOG_ERR, "v4l", "%s: Unable to open device: %s\n", va->va_path, @@ -487,7 +487,7 @@ v4l_adapter_probe(const char *path) { int fd; - fd = open(path, O_RDWR | O_NONBLOCK); + fd = tvh_open(path, O_RDWR | O_NONBLOCK, 0); if(fd == -1) { if(errno != ENOENT) diff --git a/src/webui/webui.c b/src/webui/webui.c index 90ac83bdc..d5dc85baf 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -102,7 +102,7 @@ page_static_file(http_connection_t *hc, const char *remain, void *opaque) snprintf(path, sizeof(path), "%s/%s", base, remain); - if((fd = open(path, O_RDONLY)) < 0) { + if((fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) { tvhlog(LOG_ERR, "webui", "Unable to open file %s -- %s", path, strerror(errno)); return 404; @@ -222,7 +222,7 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque) content = "video/x-matroska"; } - fd = open(fname, O_RDONLY); + fd = open(fname, O_RDONLY | O_CLOEXEC); free(fname); if(fd < 0) return 404; diff --git a/src/wrappers.c b/src/wrappers.c new file mode 100644 index 000000000..1afd5f821 --- /dev/null +++ b/src/wrappers.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include "tvhead.h" + +int +tvh_open(const char *pathname, int flags, mode_t mode) +{ + return open(pathname, flags | O_CLOEXEC, mode); +}