diff options
author | ho.namkoong <ho.namkoong@samsung.com> | 2013-12-13 16:04:53 +0900 |
---|---|---|
committer | ho.namkoong <ho.namkoong@samsung.com> | 2013-12-13 16:04:53 +0900 |
commit | 90f7c6fb9c1ccf01b45362849819863696e3bd0d (patch) | |
tree | 121ee65851d5c33511bb52dfc70824cdf9b01125 | |
parent | 16e2bd44b6669e7f49a506bc7dbc0ef62443331e (diff) | |
download | sdb-90f7c6fb9c1ccf01b45362849819863696e3bd0d.tar.gz sdb-90f7c6fb9c1ccf01b45362849819863696e3bd0d.tar.bz2 sdb-90f7c6fb9c1ccf01b45362849819863696e3bd0d.zip |
SDB: Fix web debug bug and add packet tracing in log
Change-Id: Ic7e54706d4278263d483088a1d7ee3359c36b9db
Signed-off-by: ho.namkoong <ho.namkoong@samsung.com>
-rw-r--r-- | src/log.c | 21 | ||||
-rw-r--r-- | src/log.h | 10 | ||||
-rwxr-xr-x | src/sockets.c | 4 | ||||
-rwxr-xr-x | src/transport.c | 22 | ||||
-rwxr-xr-x | src/utils_unix.c | 2 |
5 files changed, 39 insertions, 20 deletions
@@ -24,6 +24,10 @@ #include "strutils.h" int loglevel_mask; +//0 do not trace packet +//1 trace packet with MAX_DUMP_HEX_LEN +//2 trace full packet +int trace_packet = 0; static struct { char* name; @@ -38,8 +42,10 @@ static struct { { NULL, 0 } }; +//logging full packet void logging_hex(char* hex, char* asci) { + sdb_mutex_lock(&D_lock, NULL); int hex_len = s_strnlen(hex, 4096); char* hex_ptr = hex; @@ -73,8 +79,9 @@ void logging_hex(char* hex, char* asci) { } fprintf(stderr, "%s\n", asci_ptr); - - + fprintf(stderr, "--------------LOGGING HEX END--------------\n\n"); + fflush(stderr); + sdb_mutex_unlock(&D_lock, NULL); } void logging(LogLevel level, const char *filename, const char *funcname, int line_number, const char *fmt, ...) { @@ -148,7 +155,17 @@ void log_init(void) { char* sdb_debug = NULL; + if ((sdb_debug = getenv(DEBUG_ENV))) { log_parse(sdb_debug); } + + char* trace_packet; + trace_packet = getenv(TRACE_PACKET); + if(!strcmp(trace_packet, "true")) { + trace_packet = 2; + } + else if ((loglevel_mask & (1 << SDBLOG_INFO)) != 0) { + trace_packet = 1; + } } @@ -19,7 +19,9 @@ #define SDB_TRACE 1 #define DEBUG_ENV "SDB_DEBUG" +#define TRACE_PACKET "SDB_TRACE_PACKET" extern int loglevel_mask; +extern int trace_packet; typedef enum { SDBLOG_FATAL = 1, @@ -53,11 +55,9 @@ typedef enum { do { if ((loglevel_mask & (1 << SDBLOG_FIXME)) != 0) { \ logging(SDBLOG_FIXME, __FILE__, __FUNCTION__, __LINE__, args); } } while(0) -#define LOG_HEX(hex, asci) \ - do { \ - logging_hex(hex, asci); } while(0) - - +#define LOG_PACKET(args...) \ + do { if ((loglevel_mask & (1 << SDBLOG_INFO)) != 0 || trace_packet) { \ + logging(SDBLOG_INFO, __FILE__, __FUNCTION__, __LINE__, args); } } while(0) void log_init(void); void logging(LogLevel level, const char *filename, const char *funcname, int line_number, const char *fmt, ...); diff --git a/src/sockets.c b/src/sockets.c index 62dbc4c..e64d685 100755 --- a/src/sockets.c +++ b/src/sockets.c @@ -484,10 +484,6 @@ static void local_socket_event_func(int fd, unsigned ev, void *_s) p->len = MAX_PAYLOAD - avail; //TODO HOT PATCH FOR 2048. - if(p->len > 0 && p->len % 512 == 0) { - s->char_2048 = p->data[--p->len]; - s->check_2048 = 1; - } if(peer_enqueue(s, p) < 0) { //local socket is already closed by peer or should not close the socket. diff --git a/src/transport.c b/src/transport.c index 91c3535..a5ca199 100755 --- a/src/transport.c +++ b/src/transport.c @@ -76,11 +76,13 @@ int asprintf( char **sptr, char *fmt, ... ) //#define MAX_DUMP_HEX_LEN 4096 static void dump_hex( const unsigned char* ptr, size_t len) { - if(SDB_TRACING) { + if(trace_packet) { char hex_str[]= "0123456789abcdef"; - if(len > MAX_DUMP_HEX_LEN) { - len = MAX_DUMP_HEX_LEN; + if(trace_packet == 1) { + if(len > MAX_DUMP_HEX_LEN) { + len = MAX_DUMP_HEX_LEN; + } } int i; @@ -102,8 +104,12 @@ static void dump_hex( const unsigned char* ptr, size_t len) } asci[len] = '\0'; - DR("HEX:'%s', ASCI:'%s'\n", hex, asci); -// LOG_HEX(hex, asci); + if(trace_packet == 1) { + LOG_PACKET("HEX:'%s', ASCI:'%s'\n", hex, asci); + } + else { + logging_hex(hex, asci); + } } } @@ -155,7 +161,7 @@ void run_transport_close(TRANSPORT* t) void dump_packet(const char* name, const char* func, PACKET* p) { - if(SDB_TRACING) { + if(trace_packet) { unsigned cmd = p->msg.command; char command[9]; @@ -182,8 +188,8 @@ void dump_packet(const char* name, const char* func, PACKET* p) snprintf(command, sizeof command, "%08x", cmd); } - D("T(%s) %s: [%s] arg0=%X arg1=%X (len=%d) (total_msg_len=%d)\n", - name, func, command, p->msg.arg0, p->msg.arg1, p->msg.data_length, p->len); + LOG_PACKET("T(%s) %s: [%s] arg0=%X arg1=%X (len=%d) (total_msg_len=%d)\n", + name, func, command, p->msg.arg0, p->msg.arg1, p->msg.data_length, p->len); dump_hex(p->data, p->msg.data_length); } } diff --git a/src/utils_unix.c b/src/utils_unix.c index 90df679..3ae9d3b 100755 --- a/src/utils_unix.c +++ b/src/utils_unix.c @@ -97,7 +97,7 @@ static int _launch_server(void) static void _start_logging(void) { const char* p = getenv(DEBUG_ENV); - if (p == NULL) { + if (p == NULL && !getenv(TRACE_PACKET)) { return; } int fd; |