Fix warning as error for V2
Change-Id: I70cfd971fda629011ba1be84fef15afea196d393
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) {