[MPlayer-dev-eng] [PATCH] Fix stream_write_buffer to make sure all requested bytes are written
Tobias Diedrich
ranma at tdiedrich.de
Tue Feb 8 15:04:54 CET 2011
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 at google.com>
Index: mplayer-patchset1/stream/stream.c
===================================================================
--- mplayer-patchset1.orig/stream/stream.c 2011-02-08 14:52:42.038460000 +0100
+++ mplayer-patchset1/stream/stream.c 2011-02-08 14:53:09.038355000 +0100
@@ -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;
}
Index: mplayer-patchset1/stream/stream_file.c
===================================================================
--- mplayer-patchset1.orig/stream/stream_file.c 2011-02-08 14:52:42.064478000 +0100
+++ mplayer-patchset1/stream/stream_file.c 2011-02-08 14:53:30.193669000 +0100
@@ -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) {
Index: mplayer-patchset1/stream/stream_smb.c
===================================================================
--- mplayer-patchset1.orig/stream/stream_smb.c 2011-02-08 14:52:42.087467000 +0100
+++ mplayer-patchset1/stream/stream_smb.c 2011-02-08 14:53:09.045335000 +0100
@@ -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){
Index: mplayer-patchset1/stream/stream_ffmpeg.c
===================================================================
--- mplayer-patchset1.orig/stream/stream_ffmpeg.c 2011-02-08 14:52:42.104466000 +0100
+++ mplayer-patchset1/stream/stream_ffmpeg.c 2011-02-08 14:53:09.049329000 +0100
@@ -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;
}
More information about the MPlayer-dev-eng
mailing list