]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Open all files with O_CLOEXEC
authorAndreas Öman <andreas@lonelycoder.com>
Thu, 26 Nov 2009 19:35:08 +0000 (19:35 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Thu, 26 Nov 2009 19:35:08 +0000 (19:35 +0000)
13 files changed:
Makefile
docs/html/overview.html
src/dvb/dvb_adapter.c
src/dvb/dvb_tables.c
src/dvb/dvb_transport.c
src/htsp.c
src/rawtsinput.c
src/rtsp.c
src/settings.c
src/tvhead.h
src/v4l.c
src/webui/webui.c
src/wrappers.c [new file with mode: 0644]

index 41f9b44a7100366ca1f512690968e09da57f14eb..99265fb24013d5bcb34b008d42f07f01f66c9cab 100644 (file)
--- 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 \
index 9128947b7adb30dc7bada65285ed5fc5ff5ba09e..fb2197d7b57fd5db5b05e7f15e803cf0562c97cc 100644 (file)
@@ -9,7 +9,7 @@
 </center>
 
 Tvheadend is part of the <b>HTS</b> project hosted at
-<a href="%%_SITEROOT_%%">%%_SITEROOT_%%</a>
+<a href="http://www.lonelycoder.com/hts">http://www.lonelycoder.com/hts</a>
 <p>
 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.
index 52f2b876c41170f0b24bb02c337c593524e2e8c4..25387d7d29348f6b26e00e1a7f1f3acd2456f4c3 100644 (file)
@@ -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;
index 579814f14c7161fa36d89cda74eaf0c9f02a3480..07bf0fbff17a0d28bb094cdbe972b44d44712548 100644 (file)
@@ -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) {
 
index 0865b1f86f2649a548f1d25719f2b896ae5e3595..ecd1c6d25e8a3e9fcfd28d77f2a137fe963bf001 100644 (file)
@@ -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) {
index 3e0ccb6e31f85e7e48e6ed41f1c3095528ef6ce9..f73f810fa4fff0852d3c8741c4efdcc894ca685a 100644 (file)
@@ -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);
index 5ced1b2c1d440b07c3d09187dc0e58b2bc342bb1..d36cac695eccae4ea462f6b528fb1f7798f38d9c 100644 (file)
@@ -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));
index c5920cb5b255028c68f3dab9dc499af8d3dc692c..82d1d110d69ee7daf1831f4e3e5b483d9ae9d491 100644 (file)
@@ -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);
index f1ca19cab17074f54cde9b1e612e39e3f376e864..0ebd7404d01e55604cc2263a1a9fc9a99f5c0fe9 100644 (file)
@@ -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);
index 054af3140c3e0b42b9f9ce83cc0f8a004a14daa8..ca769da539c1d3ef3b05f421c6b92558aa3b6585 100644 (file)
@@ -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 */
index 876bbd7f6ebf2709e81f53c52251964ccd127055..041c68d2857a2d0b9286b784cde1a943354c3561 100644 (file)
--- 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)
index 90ac83bdcbcb18e5c148214a23c62cb864ab20c3..d5dc85baff33e7c3e251c0f478b8d46d1bf09c3b 100644 (file)
@@ -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 (file)
index 0000000..1afd5f8
--- /dev/null
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include "tvhead.h"
+
+int
+tvh_open(const char *pathname, int flags, mode_t mode)
+{
+  return open(pathname, flags | O_CLOEXEC, mode);
+}