changeset 32794:77d81e27a176

Fix stream_write_buffer to make sure all requested bytes are written None of the calling sites to stream_write_buffer are checking the return value to see if all bytes got written. This was causing (very occasionally) problems with mencoder when using output pipes AND running under a sandbox or when being straced (ptrace is the culprit) Theoretically this problem can happen without pipes or ptrace. Only stream_file, stream_smb and stream_ffmpeg implement write_buffer and ffmpeg already handles this internally. Original patch by Sang-Uok Kum. Signed-off-by: Tobias Diedrich <ranma@google.com>
author ranma
date Thu, 10 Feb 2011 21:25:38 +0000
parents 0adeebe4e561
children 801dc49c6f33
files stream/stream.c stream/stream_ffmpeg.c stream/stream_file.c stream/stream_smb.c
diffstat 4 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream.c	Thu Feb 10 19:20:36 2011 +0000
+++ b/stream/stream.c	Thu Feb 10 21:25:38 2011 +0000
@@ -28,6 +28,7 @@
 #endif
 #include <fcntl.h>
 #include <strings.h>
+#include <assert.h>
 
 #include "config.h"
 
@@ -331,6 +332,7 @@
   if(rd < 0)
     return -1;
   s->pos += rd;
+  assert(rd == len && "stream_write_buffer(): unexpected short write");
   return rd;
 }
 
--- a/stream/stream_ffmpeg.c	Thu Feb 10 19:20:36 2011 +0000
+++ b/stream/stream_ffmpeg.c	Thu Feb 10 21:25:38 2011 +0000
@@ -33,6 +33,7 @@
 
 static int write_buffer(stream_t *s, char *buffer, int len)
 {
+    /* url_write retries internally on short writes and EAGAIN */
     int r = url_write(s->priv, buffer, len);
     return (r <= 0) ? -1 : r;
 }
--- a/stream/stream_file.c	Thu Feb 10 19:20:36 2011 +0000
+++ b/stream/stream_file.c	Thu Feb 10 21:25:38 2011 +0000
@@ -57,8 +57,16 @@
 }
 
 static int write_buffer(stream_t *s, char* buffer, int len) {
-  int r = write(s->fd,buffer,len);
-  return (r <= 0) ? -1 : r;
+  int r;
+  int wr = 0;
+  while (wr < len) {
+    r = write(s->fd,buffer,len);
+    if (r <= 0)
+      return -1;
+    wr += r;
+    buffer += r;
+  }
+  return len;
 }
 
 static int seek(stream_t *s,off_t newpos) {
--- a/stream/stream_smb.c	Thu Feb 10 19:20:36 2011 +0000
+++ b/stream/stream_smb.c	Thu Feb 10 21:25:38 2011 +0000
@@ -101,8 +101,16 @@
 }
 
 static int write_buffer(stream_t *s, char* buffer, int len) {
-  int r = smbc_write(s->fd,buffer,len);
-  return (r <= 0) ? -1 : r;
+  int r;
+  int wr = 0;
+  while (wr < len) {
+    r = smbc_write(s->fd,buffer,len);
+    if (r <= 0)
+      return -1;
+    wr += r;
+    buffer += r;
+  }
+  return len;
 }
 
 static void close_f(stream_t *s){