Modify sdb server logging policy for error log
authorgreatim <jaewon81.lim@samsung.com>
Thu, 6 Oct 2016 05:15:06 +0000 (14:15 +0900)
committerSangJin Kim <sangjin3.kim@samsung.com>
Mon, 19 Dec 2016 05:06:42 +0000 (14:06 +0900)
sdb server must left error log even if log ENV is not set

Change-Id: I04ea4bce56384307b1ee6ded7fed04fea3c7a563
Signed-off-by: greatim <jaewon81.lim@samsung.com>
Signed-off-by: SangJin Kim <sangjin3.kim@samsung.com>
src/auto_complete.c
src/fdevent.c
src/file_sync_functions.c
src/listener.c
src/log.c
src/log.h
src/sdb.c
src/sockets.c
src/transport.c
src/utils_unix.c
src/utils_windows.c

index b614762fb9b17aab09f947265600b701df6eaa87..9c5634550bb5a754ccd3e10a56133d5d289530e2 100644 (file)
@@ -205,7 +205,7 @@ static int initialize_ac(int complete) {
 
     if(ac_stdout_fd < 0) {
         print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "stdout"));
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
         return -1;
     }
 
@@ -217,7 +217,7 @@ static int initialize_ac(int complete) {
 
     if(ac_stderr_fd < 0) {
         print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "stdout"));
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
         return -1;
     }
 
@@ -231,14 +231,14 @@ static int initialize_ac(int complete) {
     if(null_fd < 0) {
         sdb_close(null_fd);
         print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_SYNC_OPEN_FAIL, "/dev/null"));
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
         return -1;
     }
 
     if(dup2(null_fd, STDOUT_FILENO) < 0){
         sdb_close(null_fd);
         print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "/dev/null"));
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
         return -1;
     }
 
@@ -246,7 +246,7 @@ static int initialize_ac(int complete) {
         sdb_close(null_fd);
         fprintf(stderr, "error: exception happend while duplicating /dev/null to the stderr '%s'\n", strerror(errno));
         print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "/dev/null"));
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
         return -1;
     }
 
index 59fd2faeeb9bebb5987885dc0c1ef8d1779b798e..6b7143123cd8100902bd1c415999671288234a5a 100755 (executable)
@@ -74,7 +74,7 @@ void fdevent_unregister(FD_EVENT *fde)
         LOG_FATAL("fdevent out of range FD(%d)\n", fd);
     }
     else if(fdevent_map_get(fd) != fde) {
-        LOG_FATAL("fd event out of sync");
+        LOG_FATAL("fd event out of sync\n");
     }
     else {
         fdevent_map_remove(fd);
index e0da35f3bef8f7013c1a1f2ded17ad308ecb5e10..38ed958cf1aa9d239110fe008073757fa6661ddc 100644 (file)
@@ -90,7 +90,7 @@ int initialize_remote(char* path) {
 
     if(fd < 0) {
         print_error(SDB_MESSAGE_FATAL, ERR_SYNC_OPEN_CHANNEL_FAIL, ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     return fd;
@@ -141,12 +141,12 @@ int _stat_remote(int fd, char* path, struct stat* st, int print_err) {
     if(writex(fd, &msg.req, sizeof(msg.req)) ||
        writex(fd, path, len)) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_STAT_FAIL, path), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     if(readx(fd, &msg.stat, sizeof(msg.stat))) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_STAT_FAIL, path), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     if(msg.stat.id != sync_stat) {
@@ -218,7 +218,7 @@ int readopen_remote(int fd, char* srcp, struct stat* st) {
 
     if(writex(fd, &msg.req, sizeof(msg.req)) || writex(fd, srcp, len)) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_OPEN_FAIL, srcp), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
     return fd;
 }
@@ -290,7 +290,7 @@ int writeopen_remote(int fd, char* dstp, struct stat* st) {
             writex(fd, dstp, len) ||
             writex(fd, tmp, r)) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_OPEN_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     return fd;
@@ -312,13 +312,13 @@ int writeclose_remote(int fd, char* dstp, struct stat* st) {
 
     if(writex(fd, &msg.data, sizeof(msg.data))) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_CLOSE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
 
     if(readx(fd, &msg.status, sizeof(msg.status))) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_CLOSE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     if(msg.status.id != sync_okay) {
@@ -406,7 +406,7 @@ int readfile_remote(int fd, char* srcpath, struct stat* st, FILE_BUFFER* buffer)
 
     if(readx(fd, &(msg.data), sizeof(msg.data))) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
     id = msg.data.id;
     buffer->size = ltohl(msg.data.size);
@@ -445,7 +445,7 @@ int readfile_remote(int fd, char* srcpath, struct stat* st, FILE_BUFFER* buffer)
     //fail
     if(readx(fd, buffer->data, buffer->size)) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     //write and continue load
@@ -463,7 +463,7 @@ int writefile_local(int fd, char* dstp, FILE_BUFFER* sbuf, SYNC_INFO* sync_info)
          * if local write fails, protocol conflict happens unless we receive sync_done from remote
          */
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_WRITE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
     }
 
     sync_info->total_bytes += len;
@@ -476,7 +476,7 @@ int writefile_remote(int fd, char* dstp, FILE_BUFFER* sbuf, SYNC_INFO* sync_info
 
     if(writex(fd, sbuf, sizeof(unsigned)*2 + size)) {
         print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_WRITE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
-        LOG_ERROR(strerror(errno));
+        LOG_ERROR("%s\n", strerror(errno));
      }
 
     sync_info->total_bytes += size;
@@ -581,7 +581,7 @@ int getdirlist_remote(int fd, char* src_dir, char* dst_dir, LIST_NODE** dirlist,
         char file_name[257];
         if(readx(fd, file_name, len)) {
             print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), ERR_GENERAL_CONNECTION_FAIL);
-            LOG_ERROR(strerror(errno));
+            LOG_ERROR("%s\n", strerror(errno));
         }
         file_name[len] = 0;
 
index c451cff48fd7953f95c59c24ca289f1ac7b45667..70e2b2daed1b416dee9d229593ac2c30c52a97b1 100755 (executable)
@@ -64,7 +64,7 @@ int install_listener(int local_port, int connect_port, TRANSPORT* transport, LIS
     listener = find_listener(local_port);
     if(listener != NULL) {
         if(listener->type != forwardListener) {
-            LOG_ERROR("can not repurpose if it is not forward listener");
+            LOG_ERROR("can not repurpose if it is not forward listener\n");
             return -1;
         }
 
@@ -141,7 +141,7 @@ int install_listener2(int local_port, char* connect_to, TRANSPORT* transport, LI
     listener = find_listener(local_port);
     if(listener != NULL) {
         if(listener->type != forwardListener) {
-            LOG_ERROR("can not repurpose if it is not forward listener");
+            LOG_ERROR("can not repurpose if it is not forward listener\n");
             return -1;
         }
 
index 5969f784a9134ebffba53de8864522cbcad91d35..30e4bfbec17e0586842222173853dd27432fbe7a 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -23,7 +23,7 @@
 #include "utils.h"
 #include "strutils.h"
 
-int loglevel_mask;
+int loglevel_mask = 0;
 //0 do not trace packet
 //1 trace packet with MAX_DUMP_HEX_LEN
 //2 trace full packet
@@ -225,7 +225,6 @@ void log_init(void)
 {
     char*  sdb_debug = NULL;
 
-
     if ((sdb_debug = getenv(DEBUG_ENV))) {
         log_parse(sdb_debug);
     }
@@ -239,3 +238,12 @@ void log_init(void)
         trace_packet = 1;
     }
 }
+
+void log_init_server(void)
+{
+    // policy changed (2016-10-05)
+    // sdb server print fatal & error log even if no SDB_DEBUG env is set
+    loglevel_mask |= 1 << SDBLOG_FATAL;
+    loglevel_mask |= 1 << SDBLOG_ERROR;
+}
+
index 5fc88514efbfd7b47381542598c7ce19587435cb..4a88c94a9f9fb58a05befab5dacaaaa63e37efd4 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -74,6 +74,7 @@ typedef enum {
             logging(SDBLOG_INFO, __FILE__, __FUNCTION__, __LINE__, args); } } while(0)
 
 void log_init(void);
+void log_init_server(void);
 void logging(LogLevel level, const char *filename, const char *funcname, int line_number, const char *fmt, ...);
 void logging_hex(char* hex, char* asci);
 void print_error(int level, const char* situation, const char* reason);
index 61cb504dfe747375d8a7f66180fa4df6ea7b4f91..fd34aa441736000160aa8f4f951ba0ff6398051f 100755 (executable)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -168,6 +168,7 @@ int sdb_main(int is_daemon, int server_port)
         _exit(1);
     }
     if (is_daemon) {
+        log_init_server();
         start_logging();
     }
     LOG_INFO("only_detect_tizen_device: %d\n", g_only_detect_tizen_device);
index d2b3d3cd6c4c5cb51beb5a971dc10800503004bf..694b111c33e98db31861dc6069e25a5168e40d8e 100755 (executable)
@@ -897,7 +897,7 @@ sendfail:
                                return 0;
                        }
                        p->msg.arg0 = ENCR_SET_ON_REQ;  // Hello Msg임을 구분
-                       static int sessionID = 0; 
+                       static int sessionID = 0;
                        t->sessionID = sessionID; // 연결당 암호화 키 값을 위한 session ID 유지
                        if((retVal = security_init(t->sessionID, NULL)) == 1) // 암호화 handshaking을 위한 init 호출
                        {
@@ -926,10 +926,10 @@ sendfail:
                                {
                                        security_deinit(t->sessionID); // init에 실패한 경우, 해당 session에 대해 deinit
                                }
-                               
+
                                return 0;
                        }
-                       
+
                }
                else if(!strncmp(service+11, "off", 3)){ // encrytption off
                        if(t->encryption == ENCR_OFF){ // 해당 연결이 이미 암호화 모드 off인 경우
@@ -950,13 +950,13 @@ sendfail:
                        return -3;
                }
                else{
-                       LOG_ERROR("parsing encryption commands failed\n"); 
+                       LOG_ERROR("parsing encryption commands failed\n");
                        sendfailmsg(socket->fd, "Failed : Invalid encryption command");
                        return 0;
                }
-               
+
        }
-               
+
 #endif
 
     return -1;
@@ -1425,7 +1425,7 @@ static int smart_socket_enqueue(SDB_SOCKET *s, PACKET *p)
                     err_str = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_OFFLINE, NULL);
                 }
             }
-            LOG_ERROR("LS(%X) get no transport", s->local_id);
+            LOG_ERROR("LS(%X) get no transport\n", s->local_id);
             sendfailmsg(s->fd, err_str);
             goto fail;
         }
index b615dbd2e2a9364ae15b2c6e03e9aa80a40cf4e0..5e4349d610779b5f5da1cfb0c39e5ecc29af0dc6 100755 (executable)
@@ -875,7 +875,7 @@ void wakeup_select_func(int _fd, unsigned ev, void *data) {
 
     int length = readx(_fd, &t_packet, sizeof(t_packet));
     if(length == -1) {
-        LOG_DEBUG("wakeup_select_func(): cannot read FD(%d) transport packet", _fd);
+        LOG_DEBUG("wakeup_select_func(): cannot read FD(%d) transport packet\n", _fd);
     }
 
     TRANSPORT* t= t_packet->t;
@@ -989,9 +989,9 @@ void wakeup_select_func(int _fd, unsigned ev, void *data) {
                 send_auth_response(p->data, p->msg.data_length, t);
             } else {
                 /* No more private keys to try, send the public key */
-                LOG_DEBUG("before send auth ok !!");
+                LOG_DEBUG("before send auth ok !!\n");
                 send_auth_publickey(t);
-                LOG_DEBUG("send auth ok !!");
+                LOG_DEBUG("send auth ok !!\n");
             }
 #if 0 // daemon code (never happened in sdb server)
         } else if (p->msg.arg0 == ADB_AUTH_SIGNATURE) {
index 39ee9a5c77400cc74fcc8eee4fbaf1797cb04d6c..b39d5ceb3884b152c51230a5be25b1d287b5a8ed 100755 (executable)
@@ -101,12 +101,11 @@ static int _launch_server(int only_detect_tizen_device)
 
 static void _start_logging(void)
 {
-    const char*  p = getenv(DEBUG_ENV);
-    if (p == NULL && !getenv(TRACE_PACKET)) {
-        return;
-    }
     int fd;
 
+    if (loglevel_mask == 0)
+        return;
+
     fd = unix_open("/dev/null", O_RDONLY);
     if (fd >= 0) {
         dup2(fd, 0);
@@ -118,7 +117,7 @@ static void _start_logging(void)
 
     fd = unix_open("/tmp/sdb.log", O_WRONLY | O_CREAT | O_APPEND, 0640);
     if(fd < 0) {
-        print_error(SDB_MESSAGE_ERROR ,ERR_GENERAL_LOG_FAIL, F(ERR_SYNC_OPEN_FAIL, "/tmp/sdb/log"));
+        print_error(SDB_MESSAGE_ERROR ,ERR_GENERAL_LOG_FAIL, F(ERR_SYNC_OPEN_FAIL, "/tmp/sdb.log"));
         fd = unix_open("/dev/null", O_WRONLY);
         if( fd < 0 ) {
             print_error(SDB_MESSAGE_ERROR ,ERR_GENERAL_LOG_FAIL, F(ERR_SYNC_OPEN_FAIL, "/dev/null"));
@@ -153,7 +152,7 @@ static void  _close_on_exec(int  fd)
 {
     int ret = fcntl( fd, F_SETFD, FD_CLOEXEC );
     if (ret == -1)
-        LOG_ERROR("failed to set the file descriptor '%d': %s",fd ,strerror(errno));
+        LOG_ERROR("failed to set the file descriptor '%d': %s\n",fd ,strerror(errno));
 }
 
 static void _keep_alive(int fd, int onoff, int cnt, int idle, int interval)
index 5bb7d06418b155f5051f4a79ada0fcbdeafbb9ae..151fd064ad1cff24a5c29911069fb1386c3d2ccd 100755 (executable)
@@ -198,15 +198,13 @@ static int _launch_server(int only_detect_tizen_device) {
 
 static void _start_logging(void)
 {
-    const char*  p = getenv(DEBUG_ENV);
-    if (p == NULL) {
-        return;
-    }
-
     char    temp[ MAX_PATH ];
     FILE*   fnul;
     FILE*   flog;
 
+    if (loglevel_mask == 0)
+        return;
+
     GetTempPath( sizeof(temp) - 8, temp );
     strcat( temp, "sdb.log" );