]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Don't try to writev() longer vectors than sysconf(_SC_IOV_MAX) says
authorAndreas Öman <andreas@lonelycoder.com>
Sun, 12 Sep 2010 19:23:48 +0000 (19:23 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Sun, 12 Sep 2010 19:23:48 +0000 (19:23 +0000)
src/dvr/dvr_db.c
src/dvr/mkmux.c

index 98aa275178cccb34d41c476cb3e5153b327461e9..bf4e80835fd671988e1b7ca5fc1f0c69738d59c0 100644 (file)
@@ -38,10 +38,10 @@ int dvr_flags;
 int dvr_extra_time_pre;
 int dvr_extra_time_post;
 char *dvr_postproc;
+int dvr_iov_max;
 
 static int de_tally;
 
-
 struct dvr_entry_list dvrentries;
 
 static void dvr_entry_save(dvr_entry_t *de);
@@ -721,6 +721,8 @@ dvr_init(void)
   struct stat st;
   uint32_t u32;
 
+  dvr_iov_max = sysconf(_SC_IOV_MAX);
+
   /* Default settings */
 
   dvr_retention_days = 31;
index 3b2b5ca1d92ffb077447c089d03233f4e538166f..d19dd489c3e032dee2ebb981411d888a56c9f0f4 100644 (file)
@@ -31,6 +31,8 @@
 #include "mkmux.h"
 #include "ebml.h"
 
+extern int dvr_iov_max;
+
 TAILQ_HEAD(mk_cue_queue, mk_cue);
 
 #define MATROSKA_TIMESCALE 1000000 // in nS
@@ -311,14 +313,20 @@ mk_write_to_fd(mk_mux_t *mkm, htsbuf_queue_t *hq)
     iov[i  ].iov_base = hd->hd_data     + hd->hd_data_off;
     iov[i++].iov_len  = hd->hd_data_len - hd->hd_data_off;
   }
-  
-  if(writev(mkm->fd, iov, i) != hq->hq_size) {
-    mkm->error = errno;
-    tvhlog(LOG_ERR, "MKV", "%s: Unable to write -- %s",
-          mkm->filename, strerror(errno));
-  } else {
-    mkm->fdpos += hq->hq_size;
-  }
+
+  do {
+    ssize_t r;
+    int iovcnt = i < dvr_iov_max ? i : dvr_iov_max;
+    if((r = writev(mkm->fd, iov, iovcnt)) == -1) {
+      mkm->error = errno;
+      tvhlog(LOG_ERR, "MKV", "%s: Unable to write -- %s",
+            mkm->filename, strerror(errno));
+      return;
+    }
+    mkm->fdpos += r;
+    i -= iovcnt;
+    iov += iovcnt;
+  } while(i);
 }