Fix code warning.

Change-Id: Ib11fb49f528d3688351ae349d5b4e307c28b3967
diff --git a/mbtk/libmbtk_lib/common/mbtk_adc.c b/mbtk/libmbtk_lib/common/mbtk_adc.c
index 55cce7c..601d9b0 100755
--- a/mbtk/libmbtk_lib/common/mbtk_adc.c
+++ b/mbtk/libmbtk_lib/common/mbtk_adc.c
@@ -16,6 +16,9 @@
 #include <sys/stat.h>
 #include <sys/statfs.h>
 #include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+
 #include "mbtk_log.h"
 #include "mbtk_type.h"
 #include "mbtk_adc.h"
diff --git a/mbtk/libmbtk_lib/common/mbtk_at.c b/mbtk/libmbtk_lib/common/mbtk_at.c
index 8721a52..8262756 100755
--- a/mbtk/libmbtk_lib/common/mbtk_at.c
+++ b/mbtk/libmbtk_lib/common/mbtk_at.c
@@ -15,12 +15,15 @@
 #include "mbtk_log.h"
 
 #define MBTK_AT_SOCK "/tmp/atcmd_at"
+
+#ifndef TEMP_FAILURE_RETRY
 #define TEMP_FAILURE_RETRY(exp) ({         \
     typeof (exp) _rc;                      \
     do {                                   \
         _rc = (exp);                       \
     } while (_rc == -1 && errno == EINTR); \
     _rc; })
+#endif
 
 static char *at_rsp_complete_tag[] = {
         "OK",
diff --git a/mbtk/libmbtk_lib/common/mbtk_bs_position.c b/mbtk/libmbtk_lib/common/mbtk_bs_position.c
index 0119ae5..0b1d6e3 100755
--- a/mbtk/libmbtk_lib/common/mbtk_bs_position.c
+++ b/mbtk/libmbtk_lib/common/mbtk_bs_position.c
@@ -245,7 +245,6 @@
 
 struct mbtk_bs_ubus_t *bs_ril_init(struct mbtk_bs_ubus_t *bs)
 {
-	int ret;
 
 	mbtk_bs_ubus = malloc(sizeof(struct mbtk_bs_ubus_t));
 	if (!mbtk_bs_ubus) {
diff --git a/mbtk/libmbtk_lib/common/mbtk_debug.c b/mbtk/libmbtk_lib/common/mbtk_debug.c
index e9280c9..23e8431 100755
--- a/mbtk/libmbtk_lib/common/mbtk_debug.c
+++ b/mbtk/libmbtk_lib/common/mbtk_debug.c
@@ -28,6 +28,8 @@
 #include <time.h>
 #include <sys/time.h>
 #include <stdarg.h>
+#include <execinfo.h>
+#include <cutils/properties.h>
 
 #include "mbtk_type.h"
 #include "mbtk_log.h"
@@ -57,7 +59,7 @@
 
 
 static char proc_name[100];
-static char proc_dump_name[100];
+static char proc_dump_name[100 * 2];
 static int proc_dump_fd = -1;
 
 #ifdef HAS_ULSLIB
@@ -85,7 +87,9 @@
         tmp++;
         *tmp = '\n';
 
-        write(proc_dump_fd, buf, strlen(buf));
+        if(write(proc_dump_fd, buf, strlen(buf)) != strlen(buf)) {
+            // Do nothing.
+        }
 
         va_end(ap);
     }
@@ -264,7 +268,7 @@
 
 #if 1
 #define BACKTRACE_SIZE 32
-void sigsegv_handler_with_thread(int signo) {
+void sigsegv_handler_with_thread(int signo,siginfo_t *info, void *context) {
     struct timeval log_time;
     char tmp[50] = {0};
     gettimeofday(&log_time, NULL);
diff --git a/mbtk/libmbtk_lib/common/mbtk_log.c b/mbtk/libmbtk_lib/common/mbtk_log.c
index fcdf0b1..3ffca33 100755
--- a/mbtk/libmbtk_lib/common/mbtk_log.c
+++ b/mbtk/libmbtk_lib/common/mbtk_log.c
@@ -35,7 +35,7 @@
 static int tlog_fd = -1;
 // Default for radio log.
 static int syslog_radio_enable = 2;
-static FILE* logfile = NULL;
+//static FILE* logfile = NULL;
 static int signal_fd = -1;
 
 static bool log_level_printed = FALSE;
@@ -88,6 +88,7 @@
     va_list ap;
     struct timeval log_time;
     int length = 0;
+    int ret = 0;
 
     va_start(ap, format);
     length = vsnprintf(buf, sizeof(buf), format, ap);
@@ -111,10 +112,13 @@
         struct tm* tm_t = localtime(&(log_time.tv_sec));
         strftime(tmp, 50, "%F %T", tm_t);
         snprintf(tmp + strlen(tmp), sizeof(tmp) - strlen(tmp), " %d<%d>:", (int)(log_time.tv_usec / 1000), level);
-        write(tlog_fd, tmp, strlen(tmp));
-        write(tlog_fd, buf, length);
+        ret = write(tlog_fd, tmp, strlen(tmp));
+        ret = write(tlog_fd, buf, length);
         if (buf[length - 1] != '\n') {
-            write(tlog_fd, "\n", 1);
+            ret = write(tlog_fd, "\n", 1);
+            if(ret) {
+                // Donothing.
+            }
         }
         if (tlog_fd > 2) {
             fsync(tlog_fd);
@@ -164,7 +168,6 @@
     char buff[256];
     int size = 0;
     int ret = 0;
-    int i = 0;
     static struct sockaddr_un srv_addr;
 
     if(signal_fd < 0) {
diff --git a/mbtk/libmbtk_lib/common/mbtk_ntp.c b/mbtk/libmbtk_lib/common/mbtk_ntp.c
index 5b23e37..704643a 100755
--- a/mbtk/libmbtk_lib/common/mbtk_ntp.c
+++ b/mbtk/libmbtk_lib/common/mbtk_ntp.c
@@ -72,14 +72,12 @@
 {
     char version = 1;
     long tmp_wrd;
-    int port;
     time_t timer;
     strcpy(protocol, NTPV4);
     /*判断协议版本*/
     if(!strcmp(protocol, NTPV1)||!strcmp(protocol, NTPV2)||!strcmp(protocol, NTPV3)||!strcmp(protocol, NTPV4))
     {
         memset(packet, 0, NTP_PCK_LEN);
-        port = NTP_PORT;
         /*设置 16 字节的包头*/
         version = protocol[5] - 0x30;
         tmp_wrd = htonl((LI << 30)|(version << 27) \
@@ -102,7 +100,6 @@
     }
     else if (!strcmp(protocol, TIME))/* "TIME/UDP" */
     {
-        port = TIME_PORT;
         memset(packet, 0, 4);
         return 4;
     }
@@ -117,7 +114,7 @@
     struct timeval block_time;
     char data[NTP_PCK_LEN * 8];
     socklen_t data_len = addr->ai_addrlen;
-    int packet_len, count = 0, result, i,re;
+    int packet_len, count = 0, result;
 
     /* 组织请求报文 */
     if (!(packet_len = construct_packet(data)))
diff --git a/mbtk/libmbtk_lib/common/mbtk_utils.c b/mbtk/libmbtk_lib/common/mbtk_utils.c
index fe4d716..afade99 100755
--- a/mbtk/libmbtk_lib/common/mbtk_utils.c
+++ b/mbtk/libmbtk_lib/common/mbtk_utils.c
@@ -561,9 +561,56 @@
         }
     }
 
-    ftruncate(fd, 0);
+    if(ftruncate(fd, 0)) {
+        LOGE("ftruncate(0) fail.");
+        return -1;
+    }
+
     sprintf(buff, "%ld", (long)getpid());
-    write(fd, buff, strlen(buff) + 1);
-    return 0;
+    if(write(fd, buff, strlen(buff) + 1) == strlen(buff) + 1) {
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+void mbtk_system(const void* cmd)
+{
+    if(cmd) {
+        int ret = system(cmd);
+        if(ret == -1 || ret == 127) {
+            LOGD("system(%s) fail.", cmd);
+        }
+    }
+}
+
+void mbtk_write(int fd,const void *buf, size_t len)
+{
+    if(fd >= 0 && buf) {
+        int ret = write(fd, buf, len);
+        if(ret < 0) {
+            LOGD("write() fail:%d", errno);
+        }
+    }
+}
+
+void mbtk_read(int fd,void *buf, size_t len)
+{
+    if(fd >= 0 && buf) {
+        int ret = read(fd, buf, len);
+        if(ret < 0) {
+            LOGD("read() fail:%d", errno);
+        }
+    }
+}
+
+void mbtk_close(int fd)
+{
+    if(fd >= 0) {
+        int ret = close(fd);
+        if(ret < 0) {
+            LOGD("close() fail:%d", errno);
+        }
+    }
 }