修复mbtk_logd进程 read log_radio buffer 节点大小,新增日志落盘功能

Change-Id: I3f1a1d148be26bad19b2e66b0ca7536df1e9c483
diff --git a/mbtk/mbtk_logd/alog_read.c b/mbtk/mbtk_logd/alog_read.c
index cfb7556..6ca249b 100755
--- a/mbtk/mbtk_logd/alog_read.c
+++ b/mbtk/mbtk_logd/alog_read.c
@@ -22,6 +22,9 @@
 #define    RADIOLOG_BUFF_SIZE (4*1024)
 #define    MAX_BUFFER_SIZE (8*1024)
 
+#define LOGGER_ENTRY_MAX_LEN (5*1024)
+
+
 typedef enum android_LogPriority {
     ANDROID_LOG_UNKNOWN = 0,
     ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */
@@ -56,6 +59,9 @@
 
 int tcp_connect(char* ip, int port);
 
+extern int tmp_rd_fd;
+extern char radiolog_buff[MAX_BUFFER_SIZE];
+
 void hex_print(char* buf, int len)
 {
     int i;
@@ -203,7 +209,7 @@
 {
     char priChar;
     char timeBuf[32];
-    char defaultBuffer[512] = {0};
+    char defaultBuffer[LOGGER_ENTRY_MAX_LEN] = {0};
     size_t totalLen;
     int index = 0;
     int len = 0;
@@ -213,7 +219,8 @@
     static char buffer[MAX_BUFFER_SIZE] = {0};
     static int buffer_index = 0;
 
-    if(access(tmp_log, W_OK) != 0)
+    
+    if(fcntl(fd_radio, F_GETFL) == -1 || access(tmp_log, W_OK) != 0)
     {
         fd_radio = open(tmp_log, O_CREAT | O_WRONLY| O_APPEND, 0600);
         if (fd_radio < 0)
@@ -221,7 +228,7 @@
             fprintf(stderr, "failed to open %s: %s\n", tmp_log, strerror(errno));
             exit(-1);
         }
-
+        tmp_rd_fd = fd_radio;
     }
 
 
@@ -233,7 +240,8 @@
             fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
             exit(-1);
         }
-
+        tmp_rd_fd = fd_radio;
+      
     }
 
     if(fileter_log(entry->priority, entry->tag, config->filter_list))
@@ -257,28 +265,24 @@
             defaultBuffer[index] ^= 1;
         }
     }
-
-
-    if(buffer_index >= RADIOLOG_BUFF_SIZE)
+    
+    if(buffer_index + totalLen >= RADIOLOG_BUFF_SIZE && buffer_index < RADIOLOG_BUFF_SIZE)
     {
-        // Flush the buffer if it's full
-        if (write(fd_radio, buffer, buffer_index) < 0)
+        memcpy(buffer + buffer_index, defaultBuffer, totalLen);
+        buffer_index += totalLen;
+        if (write(fd_radio, buffer, buffer_index) < 0) 
         {
             perror("write error");
+            close(fd_radio);
             return -1;
         }
         buffer_index = 0; // Reset buffer index after flushing
     }
-
-    if(totalLen < RADIOLOG_BUFF_SIZE)
-    {
-        //copy buf to buffer
-        memcpy(buffer + buffer_index, defaultBuffer, totalLen);
-        buffer_index += totalLen;
-    }
     else
     {
-        mbtk_write(fd_radio, defaultBuffer, totalLen);
+        memcpy(buffer + buffer_index, defaultBuffer, totalLen);
+        buffer_index += totalLen;
+        memcpy(radiolog_buff,buffer,buffer_index);
     }
 
 
@@ -290,7 +294,7 @@
     int dev_fd, ret;
 //    int log_fd;
     AndroidLogEntry entry;
-    char buf[512] = {0};
+    char buf[LOGGER_ENTRY_MAX_LEN] = {0};
     static struct file_list_t file_list;
     config = (log_config_entry *)argv;
 
@@ -330,9 +334,16 @@
 
         snprintf(tmp_log,sizeof(tmp_log), "%s", log_file);
         // 先将文件保存到 /tmp/log/ 目录下,后面到达 rotate_file_size 后,转移到out_path
-
-    }
-    else
+       
+        fd_radio = open(tmp_log, O_CREAT | O_WRONLY| O_APPEND, 0600);
+        if (fd_radio < 0) 
+        {
+            fprintf(stderr, "failed to open %s: %s\n", tmp_log, strerror(errno));
+            exit(-1);
+        }
+        tmp_rd_fd = fd_radio;
+    } 
+    else 
     {
         //log_fd = STDOUT_FILENO;
     }