Fix mbtk_logd warning.

Change-Id: I3df4bbbfb0e8d865fd23e8beb0752b1226410cc9
diff --git a/mbtk/mbtk_logd/syslog_read.c b/mbtk/mbtk_logd/syslog_read.c
index 94f16a8..bfc70ba 100755
--- a/mbtk/mbtk_logd/syslog_read.c
+++ b/mbtk/mbtk_logd/syslog_read.c
@@ -22,6 +22,8 @@
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/socket.h>
+#include <stdlib.h>
+#include <pthread.h>
 
 #define SYSLOG_NAMES
 #include <syslog.h>
@@ -35,6 +37,8 @@
 #include "libubus.h"
 #include "syslog.h"
 #include "log_config.h"
+
+#include "mbtk_utils.h"
 //#include "lynq/liblog.h"
 
 enum {
@@ -59,7 +63,7 @@
 	LOG_TIME,
 	__LOG_MAX
 };
-    
+
 #define    SYSLOG_BUFF_SIZE (4*1024)
 #define    MAX_BUFFER_SIZE (8*1024)
 
@@ -80,7 +84,7 @@
 static int log_size = 1 * 1024 * 1024, log_udp, log_follow = 0;
 static struct file_list_t file_list;
 static struct filter_list_t *filter_log = NULL;
-static char tmp_log[48] = {0};
+static char tmp_log[100] = {0};
 pthread_t attr = -1;
 
 static const char* getcodetext(int value, CODE *codetable) {
@@ -176,8 +180,8 @@
         int len = 0;
 	struct blob_attr *tb[__LOG_MAX];
 	struct stat s;
-	char buf[512] = {'\0'};
-	char tmp_buf[48] = {0};
+	char buf[1024 * 2] = {'\0'};
+	char tmp_buf[1024] = {0};
 	uint32_t p;
 	char *str;
 	time_t t;
@@ -185,11 +189,11 @@
 
     static char buffer[MAX_BUFFER_SIZE] = {0};
     static int buffer_index = 0;
-    
+
 	//
 	//sprintf(tmp_buf, "/tmp/log%s", strstr_tail(log_file, "/"));
 
-    
+
     snprintf(tmp_buf,sizeof(tmp_buf), "%s", log_file);
     if(access(tmp_buf, W_OK) != 0)
     {
@@ -200,9 +204,9 @@
             return -1;
         }
     }
-    
-    
-   
+
+
+
 	blobmsg_parse(log_policy, ARRAY_SIZE(log_policy), tb, blob_data(msg), blob_len(msg));
 	if (!tb[LOG_ID] || !tb[LOG_PRIO] || !tb[LOG_SOURCE] || !tb[LOG_TIME] || !tb[LOG_MSG])
 		return 1;
@@ -210,7 +214,7 @@
     if ((log_type == LOG_FILE) && log_size && (!stat(tmp_log, &s)) && (s.st_size > log_size))
     {
             sender.fd = get_rotate_file(sender.fd, log_file, &file_list);
-            if (sender.fd < 0) 
+            if (sender.fd < 0)
             {
                 fprintf(stderr, "failed to open %s: %s\n", tmp_log, strerror(errno));
                 exit(-1);
@@ -230,23 +234,23 @@
         return 0;
         //exit(-1);
     }
-	if (log_type == LOG_NET) 
+	if (log_type == LOG_NET)
 	{
 		int err;
 
 		snprintf(buf, sizeof(buf), "<%u>", p);
 		strncat(buf, c + 4, 16);
 		if (strlen(hostname) > 0) {
-			strncat(buf, hostname, sizeof(buf));
-			strncat(buf, " ", sizeof(buf));
+			strncat(buf, hostname, strlen(hostname));
+			strncat(buf, " ", 1);
 		}
 		if (strlen(log_prefix) > 0) {
-			strncat(buf, log_prefix, sizeof(buf));
-			strncat(buf, ": ", sizeof(buf));
+			strncat(buf, log_prefix, strlen(log_prefix));
+			strncat(buf, ": ", 2);
 		}
 		if (blobmsg_get_u32(tb[LOG_SOURCE]) == SOURCE_KLOG)
-			strncat(buf, "kernel: ", sizeof(buf));
-		strncat(buf, m, sizeof(buf));
+			strncat(buf, "kernel: ", strlen("kernel: "));
+		strncat(buf, m, strlen(m));
 		if (log_udp)
 			err = write(sender.fd, buf, strlen(buf));
 		else
@@ -260,8 +264,8 @@
 			sender.fd = -1;
 			uloop_timeout_set(&retry, 1000);
 		}
-	} 
-	else 
+	}
+	else
 	{
 		snprintf(buf, sizeof(buf), "%s %s.%s%s %s\n",
 			c, getcodetext(LOG_FAC(p) << 3, facilitynames), getcodetext(LOG_PRI(p), prioritynames),
@@ -275,32 +279,32 @@
                         buf[index] ^= 1;
                     }
                 }
-                
 
-         
+
+
         if (buffer_index >= SYSLOG_BUFF_SIZE)
         {
             // Flush the buffer if it's full
-            if (write(sender.fd, buffer, buffer_index) < 0) 
+            if (write(sender.fd, buffer, buffer_index) < 0)
             {
                 perror("write error");
                 return -1;
             }
             buffer_index = 0; // Reset buffer index after flushing
         }
-        
+
         if(len < SYSLOG_BUFF_SIZE)
         {
-            //copy buf to buffer 
+            //copy buf to buffer
             memcpy(buffer + buffer_index, buf, len);
             buffer_index += len;
         }
         else
         {
-            write(sender.fd, buf, len);
+            mbtk_write(sender.fd, buf, len);
         }
-        
-       
+
+
 	}
 
 	free(str);
@@ -352,7 +356,7 @@
 
     int n;
 	int array_length;
-    char* tmp_string = NULL;
+//    char* tmp_string = NULL;
 
     jsonobj = json_object_from_file(LOG_CONFIG_PATH);
     if (NULL == jsonobj) {
@@ -386,14 +390,14 @@
             }
             memset(_filter_list, 0, sizeof(struct filter_list_t));
             json_object_object_get_ex(fileterjson, "priority", &fileter_listjson);
-            char* str = json_object_get_string(fileter_listjson);
+            const char* str = json_object_get_string(fileter_listjson);
             if (str) {
                 _filter_list->priority = str[0];
                 printf("fileter_listjson: %c\n", _filter_list->priority);
             }
 
             json_object_object_get_ex(fileterjson, "tag", &fileter_listjson);
- 
+
             str = json_object_get_string(fileter_listjson);
             if (str) {
                 _filter_list->tag = strdup(str);
@@ -424,16 +428,17 @@
         free(tmp_filter_list);
         tmp_filter_list = _filter_list->next;
     }
-	
+
     return 0;
 }
 
 
-int wait_update_log_level()
+void* wait_update_log_level(void *arg)
 {
-	int i = 0;
+//	int i = 0;
 	char recvBuff[100];
-	int serverFd,clientFd,addrLen;
+	int serverFd,clientFd;
+    socklen_t addrLen;
     struct sockaddr_un serverAddr,clientAddr;
 
 	pthread_detach(pthread_self());
@@ -448,20 +453,20 @@
     if ((serverFd = socket(AF_UNIX,SOCK_STREAM,0)) < 0)
     {
         printf("err -1\n");
-        return -1;
+        return NULL;
     }
 
     if (bind(serverFd,(struct sockaddr *)&serverAddr,sizeof(serverAddr)) < 0)
     {
         printf("err -2\n");
         close(serverFd);
-        return -2;
+        return NULL;
     }
 
     if(listen(serverFd,10) < 0)
     {
         printf("err -3\n");
-        return -3;
+        return NULL;
     }
 
     while(1)
@@ -491,13 +496,13 @@
     }
     close(serverFd);
 
-	return 0;
+	return NULL;
 }
 
 int syslog_pthread_create()
 {
     int ret;
-    
+
 	ret = pthread_create(&attr, NULL, wait_update_log_level, NULL);
 
     if (ret < 0)
@@ -515,7 +520,7 @@
 	struct ubus_context *ctx;
 	uint32_t id;
 	const char *ubus_socket = NULL;
-	int ch, ret, lines = 0;
+	int ret, lines = 0;
 	static struct blob_buf b;
 	int tries = 60;
 	void* tret;
@@ -524,8 +529,8 @@
 
     pthread_detach(pthread_self());
 
-    if (NULL == argv)
-        return NULL;
+//    if (NULL == argv)
+//        return NULL;
 
 	signal(SIGPIPE, SIG_IGN);
 	uloop_init();
@@ -566,7 +571,7 @@
 	ctx = ubus_connect(ubus_socket);
 	if (!ctx) {
 		fprintf(stderr, "Failed to connect to ubus\n");
-		return -1;
+		return NULL;
 	}
 	ubus_add_uloop(ctx);
 
@@ -603,12 +608,12 @@
 		} else if (strlen(log_file) > 0) {
 			log_type = LOG_FILE;
             // 先将文件保存到 /tmp/log/ 目录下,后面到达 rotate_file_size 后,转移到out_path
-            
+
 			//sprintf(tmp_log, "/tmp/log%s", strstr_tail(log_file, "/"));
-			
+
 			//直接将log文件存储在不会掉电丢失的路径
 			snprintf(tmp_log,sizeof(tmp_log), "%s",log_file);
-            
+
 			sender.fd = open(tmp_log, O_CREAT | O_WRONLY| O_APPEND, 0600);
 			if (sender.fd < 0) {
 				fprintf(stderr, "failed to open %s: %s\n", tmp_log, strerror(errno));
@@ -627,10 +632,10 @@
 		uloop_done();
 
 	} while (ret && tries--);
-	
+
 	if (attr) {
 		if (pthread_join(attr, &tret) != 0) {
-			printf("MBTK:Join thread: %d error!\n", attr);
+			printf("MBTK:Join thread: %ld error!\n", attr);
 			exit(1);
 		}
 	}