aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-14 16:10:44 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-14 16:10:44 +0000
commit794636ecc20435a93f9f8b706af518e5595675ae (patch)
treec3a67182c20da3579938257c72b5da78f1da6797 /contrib
parenta4962bb834bbbf672d8c1e673a37bef92c7f5453 (diff)
catch read/write errors and exit if they occur (issue #6721)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@12893 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'contrib')
-rw-r--r--contrib/utils/rawplayer.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/contrib/utils/rawplayer.c b/contrib/utils/rawplayer.c
index 61944a885..2733264a0 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 <anthmct@yahoo.com>
+
+ 2006-03-10: Bruno Rocha <bruno@3gnt.net>
+ - include <stdlib.h> 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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <stdlib.h>
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;
}