From: Russell Bryant Date: Tue, 14 Mar 2006 16:10:44 +0000 (+0000) Subject: catch read/write errors and exit if they occur (issue #6721) X-Git-Tag: 1.4.0-beta1~2430 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=688e35587300140a87e414ea6c7e405ed9e2d7a8;p=thirdparty%2Fasterisk.git catch read/write errors and exit if they occur (issue #6721) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@12893 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/contrib/utils/rawplayer.c b/contrib/utils/rawplayer.c index 61944a885c..2733264a0a 100644 --- a/contrib/utils/rawplayer.c +++ b/contrib/utils/rawplayer.c @@ -1,6 +1,10 @@ /* Rawplayer.c simple raw file stdout player (c) Anthony C Minessale II + + 2006-03-10: Bruno Rocha + - include to remove compiler warning on some platforms + - check for read/write errors (avoid 100% CPU usage in some asterisk failures) */ #define BUFLEN 320 @@ -8,21 +12,25 @@ #include #include #include +#include static int deliver_file(char *path, int fdout) { - int fd = 0, bytes = 0; + int fd = 0, bytes = 0, error = 0; short buf[BUFLEN]; if ((fd = open(path,O_RDONLY))) { - while ((bytes=read(fd, buf, BUFLEN))) { - write(fdout, buf, bytes); + while ((bytes=read(fd, buf, BUFLEN)) > 0) { + if(write(fdout, buf, bytes) < 0){ + error = -2; + break; + } } if(fd) close(fd); } else return -1; - return 0; + return error; }