Revision
14948
Author
anthm
Date
2009-09-22 10:36:53 -0500 (Tue, 22 Sep 2009)

Log Message

try to rotate on failed write to cdr file

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c (14947 => 14948)


--- freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c	2009-09-22 02:59:03 UTC (rev 14947)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c	2009-09-22 15:36:53 UTC (rev 14948)
@@ -129,6 +129,7 @@
 {
 	cdr_fd_t *fd = NULL;
 	unsigned int bytes_in, bytes_out;
+	int loops = 0;
 
 	if (!(fd = switch_core_hash_find(globals.fd_hash, path))) {
 		fd = switch_core_alloc(globals.pool, sizeof(*fd));
@@ -155,12 +156,16 @@
 		do_rotate(fd);
 	}
 
-	if ((bytes_in = write(fd->fd, log_line, bytes_out)) != bytes_out) {
+	while ((bytes_in = write(fd->fd, log_line, bytes_out)) != bytes_out && ++loops < 10) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d\n", path, (int) bytes_in, (int) bytes_out);
+		do_rotate(fd);
+		switch_yield(250000);
 	}
+	
+	if (bytes_in > 0) {
+		fd->bytes += bytes_in;
+	}
 
-	fd->bytes += bytes_in;
-
   end:
 
 	switch_mutex_unlock(fd->mutex);