add T108 mbtk_logd and liblog

Change-Id: Ib486a63a423e22ca07b3568a1b3c856b23e63ea3
diff --git a/mbtk/mbtk_logd/syslog_read.c b/mbtk/mbtk_logd/syslog_read.c
index 3cae9e9..c52a6ee 100755
--- a/mbtk/mbtk_logd/syslog_read.c
+++ b/mbtk/mbtk_logd/syslog_read.c
@@ -33,6 +33,7 @@
 #include "syslog.h"
 #include "log_config.h"
 
+#define LOG_CONFIG_LEN 50
 enum {
 	LOG_STDOUT,
 	LOG_FILE,
@@ -58,7 +59,8 @@
 
 static struct uloop_timeout retry;
 static struct uloop_fd sender;
-static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname;
+//static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname;
+static char log_file[LOG_CONFIG_LEN], log_ip[LOG_CONFIG_LEN], log_port[LOG_CONFIG_LEN], log_prefix[LOG_CONFIG_LEN], pid_file[LOG_CONFIG_LEN], hostname[LOG_CONFIG_LEN];
 static int log_type = LOG_STDOUT;
 static int log_size = 1 * 1024 * 1024, log_udp, log_follow = 0;
 static struct file_list_t file_list;
@@ -184,11 +186,11 @@
 
 		snprintf(buf, sizeof(buf), "<%u>", p);
 		strncat(buf, c + 4, 16);
-		if (hostname) {
+		if (strlen(hostname) > 0) {
 			strncat(buf, hostname, sizeof(buf));
 			strncat(buf, " ", sizeof(buf));
 		}
-		if (log_prefix) {
+		if (strlen(log_prefix) > 0) {
 			strncat(buf, log_prefix, sizeof(buf));
 			strncat(buf, ": ", sizeof(buf));
 		}
@@ -258,7 +260,7 @@
 	const char *ubus_socket = NULL;
 	int ch, ret, lines = 0;
 	static struct blob_buf b;
-	int tries = 5;
+	int tries = 60;
     log_config_entry *config = (log_config_entry *)argv;
 
     pthread_detach(pthread_self());
@@ -269,7 +271,19 @@
 	signal(SIGPIPE, SIG_IGN);
 	uloop_init();
 
-    log_file = config->out_path;
+    //log_file = config->out_path;
+	memset(log_file, 0, sizeof(log_file));
+	memset(log_ip, 0, sizeof(log_ip));
+	memset(log_port, 0, sizeof(log_port));
+	memset(log_prefix, 0, sizeof(log_prefix));
+	memset(pid_file, 0, sizeof(pid_file));
+	memset(hostname, 0, sizeof(hostname));
+
+	if(config->out_path != NULL)
+	{
+		strncpy(log_file, config->out_path, LOG_CONFIG_LEN - 1);
+	}
+
     memset(&file_list, 0, sizeof(struct file_list_t));
     file_list.total = config->rotate_file_count;
     if(config->rotate_file_size)
@@ -277,8 +291,13 @@
     if(config->ip)
     {
         printf("%s %d : %s:%s\n", __FUNCTION__, __LINE__, config->ip, config->port);
-        log_ip = config->ip;
-        log_port = config->port;
+        //log_ip = config->ip;
+        strncpy(log_ip, config->ip, LOG_CONFIG_LEN - 1);
+        //log_port = config->port;
+        if(config->port != NULL)
+        {
+            strncpy(log_port, config->port, LOG_CONFIG_LEN - 1);
+        }
     }
     filter_log = config->filter_list;
     // Follow log messages
@@ -299,14 +318,13 @@
 			sleep(1);
 			continue;
 		}
-
 		blob_buf_init(&b, 0);
 		if (lines)
 			blobmsg_add_u32(&b, "lines", lines);
 		else if (log_follow)
 			blobmsg_add_u32(&b, "lines", 0);
 		if (log_follow) {
-			if (pid_file) {
+			if (strlen(pid_file) > 0) {
 				FILE *fp = fopen(pid_file, "w+");
 				if (fp) {
 					fprintf(fp, "%d", getpid());
@@ -315,16 +333,16 @@
 			}
 		}
 
-		if (log_ip && log_port) {
+		if (strlen(log_ip) > 0 && strlen(log_port) > 0) {
 			openlog("logread", LOG_PID, LOG_DAEMON);
 			log_type = LOG_NET;
 			sender.cb = log_handle_fd;
 			retry.cb = log_handle_reconnect;
 			uloop_timeout_set(&retry, 1000);
-		} else if (log_file) {
+		} 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, "/"));
+			sprintf(tmp_log, "/tmp/log%s", strstr_tail(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));
@@ -338,7 +356,7 @@
 		req.fd_cb = logread_fd_cb;
 		req.complete_cb = logread_complete_cb;
 		ubus_complete_request_async(ctx, &req);
-
+		
 		uloop_run();
 		ubus_free(ctx);
 		uloop_done();