Fix warning as error for V2
Change-Id: I70cfd971fda629011ba1be84fef15afea196d393
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_adc.c b/mbtk/libmbtk_lib_v2/common/mbtk_adc.c
index 55cce7c..601d9b0 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_adc.c
+++ b/mbtk/libmbtk_lib_v2/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_v2/common/mbtk_at.c b/mbtk/libmbtk_lib_v2/common/mbtk_at.c
index 8721a52..8262756 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_at.c
+++ b/mbtk/libmbtk_lib_v2/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_v2/common/mbtk_bs_position.c b/mbtk/libmbtk_lib_v2/common/mbtk_bs_position.c
index 0119ae5..0b1d6e3 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_bs_position.c
+++ b/mbtk/libmbtk_lib_v2/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_v2/common/mbtk_debug.c b/mbtk/libmbtk_lib_v2/common/mbtk_debug.c
index e9280c9..23e8431 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_debug.c
+++ b/mbtk/libmbtk_lib_v2/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_v2/common/mbtk_gpio.c b/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c
index d80b014..d861e3e 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c
@@ -12,7 +12,7 @@
#include "mbtk_gpio.h"
-int gpio_export(int gpio)
+int mbtk_gpio_export(int gpio)
{
int fd = -1;
char buffer[50];
@@ -44,7 +44,7 @@
return 0;
}
-int gpio_unexport(int gpio)
+int mbtk_gpio_unexport(int gpio)
{
int fd = -1;
char buffer[50];
@@ -115,7 +115,7 @@
int fd = -1;
int ret = 0;
- if(gpio_export(gpio)) {
+ if(mbtk_gpio_export(gpio)) {
return -1;
}
@@ -161,6 +161,7 @@
return -1;
}
+ memset(buffer, 0, sizeof(buffer));
if(read(fd, buffer, sizeof(buffer)) <= 0)
{
LOGE("Get gpio[%d] value fail", gpio);
@@ -178,7 +179,7 @@
int fd = -1;
int ret =-1;
- if(gpio_export(gpio)) {
+ if(mbtk_gpio_export(gpio)) {
return -1;
}
@@ -210,3 +211,34 @@
}
}
+int mbtk_gpio_value_set_2(int gpio, int value)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/value", gpio);
+ file = open(buffer,O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] value fail.", gpio);
+ return -1;
+ }
+ if(value == 0) {
+ result = write(file,"0",1);
+ } else {
+ result = write(file,"1",1);
+ }
+ if(result != 1)
+ {
+ LOGE("Set gpio[%d] value fail err =%d.", gpio, errno);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_log.c b/mbtk/libmbtk_lib_v2/common/mbtk_log.c
index fcdf0b1..ab599b4 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_log.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_log.c
@@ -21,6 +21,8 @@
#include "mbtk_log.h"
#include "mbtk_str.h"
+// extern char *__progname;
+
typedef enum {
LOG_ID_MAIN = 0,
LOG_ID_RADIO = 1,
@@ -35,11 +37,13 @@
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;
+static bool log_init = FALSE;
+
/**
* @brief mbtk_log_init
*
@@ -60,6 +64,12 @@
*/
void mbtk_log_init(char* path, char* tag)
{
+ if(log_init) {
+ return;
+ } else {
+ log_init = TRUE;
+ }
+
if (str_empty(path)) {
tlog_fd = STDOUT_FILENO;
} else if (0 == memcmp(path, "syslog", 6)) {
@@ -88,6 +98,31 @@
va_list ap;
struct timeval log_time;
int length = 0;
+ int ret = 0;
+
+ if(!log_init) {
+ char filename[64] = {0};
+ int fd = open("/proc/self/comm", O_RDONLY);
+ if(fd > 0) {
+ if(read(fd, filename, sizeof(filename)) > 0) {
+ // Delete last '\r' / '\n' / ' '
+ char *ptr = filename + strlen(filename) - 1;
+ while(ptr >= filename && (*ptr == '\r' || *ptr == '\n' || *ptr == ' '))
+ {
+ *ptr-- = '\0';
+ }
+
+ mbtk_log_init("radio", filename);
+ } else {
+ mbtk_log_init("radio", "MBTK");
+ }
+ close(fd);
+ } else {
+ mbtk_log_init("radio", "MBTK");
+ }
+
+ //mbtk_log_init("radio", __progname);
+ }
va_start(ap, format);
length = vsnprintf(buf, sizeof(buf), format, ap);
@@ -111,10 +146,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 +202,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_v2/common/mbtk_ntp.c b/mbtk/libmbtk_lib_v2/common/mbtk_ntp.c
index 5b23e37..704643a 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_ntp.c
+++ b/mbtk/libmbtk_lib_v2/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_v2/common/mbtk_utils.c b/mbtk/libmbtk_lib_v2/common/mbtk_utils.c
index fe4d716..afade99 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_utils.c
+++ b/mbtk/libmbtk_lib_v2/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);
+ }
+ }
}