add T108 mbtk_logd and liblog

Change-Id: Ib486a63a423e22ca07b3568a1b3c856b23e63ea3
diff --git a/mbtk/mbtk_logd/main.c b/mbtk/mbtk_logd/main.c
index 25dbdb1..e47bdca 100755
--- a/mbtk/mbtk_logd/main.c
+++ b/mbtk/mbtk_logd/main.c
@@ -7,6 +7,7 @@
 #include <time.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <sys/file.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "json/json.h"
@@ -69,6 +70,7 @@
     int i, n, ret;
     char* cmdval = NULL;
 
+    printf("MBTK_LOGD: in parse_config\n");
     jsonobj = json_object_from_file(LOG_CONFIG_PATH);
     if (NULL == jsonobj) {
         printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
@@ -86,8 +88,10 @@
     cmdval = json_object_get_string(tmpjson);
     printf("logd enable : %s\n", cmdval);
     json_object_put(tmpjson);
+
     /***获取data***/
     json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+
     for (i = 0 ; i < 5; i++) {
         struct filter_list_t* _filter_list = NULL;
         struct filter_list_t* tmp_filter_list = NULL;
@@ -102,16 +106,17 @@
         mbtk_log("enable: %d\n", entry->enable);
 
         json_object_object_get_ex(datajson, "name", &listjson);
-        entry->name = strdup(json_object_get_string(listjson));
-        mbtk_log("cmdval: %x, %s\n", entry->name, entry->name);
+        entry->name = json_object_get_string(listjson);
+        printf("cmdval: %x, %s\n", entry->name, entry->name);
 
         json_object_object_get_ex(datajson, "log_file", &listjson);
-        entry->out_path = strdup(json_object_get_string(listjson));
+        entry->out_path = json_object_get_string(listjson);
         mbtk_log("cmdval: %s\n", entry->out_path);
 
         json_object_object_get_ex(datajson, "log_stream", &listjson);
         if (listjson) {
-            entry->ip = strdup(json_object_get_string(listjson));
+            entry->ip = json_object_get_string(listjson);
+
             cmdval = strstr(entry->ip, ":");
             if (cmdval) {
                 entry->port = &cmdval[1];
@@ -164,7 +169,8 @@
                 _filter_list->tag = strdup(str);
                 mbtk_log("fileter_listjson: %s\n", _filter_list->tag);
             }
-            json_object_put(fileter_listjson);
+
+            //json_object_put(fileter_listjson);
             _filter_list->next = (struct filter_list_t*)malloc(sizeof(struct filter_list_t));
             if (NULL == _filter_list->next) {
                 printf("%s %d: malloc failure!\n", __FUNCTION__, __LINE__);
@@ -173,13 +179,11 @@
             tmp_filter_list = _filter_list;
             _filter_list = _filter_list->next;
         }
-        json_object_put(listjson);
     }
-    json_object_put(tmpjson);
 
     /***释放json对象***/
     json_object_put(jsonobj);
-
+    printf("MBTK_LOGD: parse_config end\n");
     return 0;
 }
 
@@ -218,18 +222,22 @@
     pthread_t pid[5] = {0};
     int i, ret;
     void* tret;
+    struct filter_list_t* _filter_list = NULL;
+
+    int lock_file = open("/tmp/mbtk_logd.lock", O_CREAT|O_RDWR, 0666);
+    int rc = flock(lock_file,LOCK_EX|LOCK_NB);
+    if(rc) {
+        if(EWOULDBLOCK == errno) {
+            printf("Error: cannot restart the mbtk_logd repeatedly\n");
+            exit(0);
+        }
+    }
 
     memset(listdata, 0, sizeof(log_config_entry) * 5);
-
     ret = parse_config(listdata);
     if (ret) {
         return -1;
     }
-    if(0 != save_pid())
-    {
-        printf("%s %d: logd exit!\n", __FUNCTION__, __LINE__);
-        return -1;
-    }
 
     printf("logd %s start !\n", __FUNCTION__);
 
@@ -258,7 +266,7 @@
             if (ret != 0) {
                 fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__);
             }
-        } else if (0 == memcmp(listdata[i].name, "/dev/tty", 8)) {
+        } else if (0 == memcmp(listdata[i].name, "/dev/ttyS0", 8)) {
             ret = pthread_create(&pid[i], NULL, common_log_thread, &listdata[i]);
             if (ret != 0) {
                 fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__);
@@ -266,6 +274,7 @@
         }
     }
 
+    
     for (i = 0; i < 5; ++i) {
         if (NULL == listdata[i].name) {
             break;