[asterisk-commits] trunk r12893 - /trunk/contrib/utils/rawplayer.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 14 09:10:47 MST 2006


Author: russell
Date: Tue Mar 14 10:10:44 2006
New Revision: 12893

URL: http://svn.digium.com/view/asterisk?rev=12893&view=rev
Log:
catch read/write errors and exit if they occur (issue #6721)

Modified:
    trunk/contrib/utils/rawplayer.c

Modified: trunk/contrib/utils/rawplayer.c
URL: http://svn.digium.com/view/asterisk/trunk/contrib/utils/rawplayer.c?rev=12893&r1=12892&r2=12893&view=diff
==============================================================================
--- trunk/contrib/utils/rawplayer.c (original)
+++ trunk/contrib/utils/rawplayer.c Tue Mar 14 10:10:44 2006
@@ -1,6 +1,10 @@
 /*
   Rawplayer.c simple raw file stdout player
   (c) Anthony C Minessale II <anthmct at yahoo.com>
+
+  2006-03-10: Bruno Rocha <bruno at 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;
 }
 
 



More information about the asterisk-commits mailing list