# HG changeset patch # User ranma # Date 1297373138 0 # Node ID 77d81e27a1767a2947ec7abe44301d2911904cb9 # Parent 0adeebe4e5611157478047d6c6dd582d4b03f229 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 diff -r 0adeebe4e561 -r 77d81e27a176 stream/stream.c --- 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 #include +#include #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; } diff -r 0adeebe4e561 -r 77d81e27a176 stream/stream_ffmpeg.c --- 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; } diff -r 0adeebe4e561 -r 77d81e27a176 stream/stream_file.c --- 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) { diff -r 0adeebe4e561 -r 77d81e27a176 stream/stream_smb.c --- 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){