From: greatim Date: Thu, 6 Oct 2016 05:15:06 +0000 (+0900) Subject: Modify sdb server logging policy for error log X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=074567a755b75420c69fa7b028b04422ecbe5952;p=sdk%2Ftools%2Fsdb.git Modify sdb server logging policy for error log sdb server must left error log even if log ENV is not set Change-Id: I04ea4bce56384307b1ee6ded7fed04fea3c7a563 Signed-off-by: greatim Signed-off-by: SangJin Kim --- diff --git a/src/auto_complete.c b/src/auto_complete.c index b614762..9c56345 100644 --- a/src/auto_complete.c +++ b/src/auto_complete.c @@ -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; } diff --git a/src/fdevent.c b/src/fdevent.c index 59fd2fa..6b71431 100755 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -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); diff --git a/src/file_sync_functions.c b/src/file_sync_functions.c index e0da35f..38ed958 100644 --- a/src/file_sync_functions.c +++ b/src/file_sync_functions.c @@ -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; diff --git a/src/listener.c b/src/listener.c index c451cff..70e2b2d 100755 --- a/src/listener.c +++ b/src/listener.c @@ -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; } diff --git a/src/log.c b/src/log.c index 5969f78..30e4bfb 100644 --- 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; +} + diff --git a/src/log.h b/src/log.h index 5fc8851..4a88c94 100644 --- 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); diff --git a/src/sdb.c b/src/sdb.c index 61cb504..fd34aa4 100755 --- 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); diff --git a/src/sockets.c b/src/sockets.c index d2b3d3c..694b111 100755 --- a/src/sockets.c +++ b/src/sockets.c @@ -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; } diff --git a/src/transport.c b/src/transport.c index b615dbd..5e4349d 100755 --- a/src/transport.c +++ b/src/transport.c @@ -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) { diff --git a/src/utils_unix.c b/src/utils_unix.c index 39ee9a5..b39d5ce 100755 --- a/src/utils_unix.c +++ b/src/utils_unix.c @@ -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) diff --git a/src/utils_windows.c b/src/utils_windows.c index 5bb7d06..151fd06 100755 --- a/src/utils_windows.c +++ b/src/utils_windows.c @@ -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" );