From: hyunuk.tak Date: Mon, 27 Apr 2020 08:39:09 +0000 (+0900) Subject: Enable logging by default X-Git-Tag: submit/tizen/20200427.103226^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F232000%2F1;p=platform%2Fcore%2Fconnectivity%2Fstc-iptables.git Enable logging by default Change-Id: Iedcdd47d199514ee3aa3c84147aa96ed38a52298 Signed-off-by: hyunuk.tak --- diff --git a/packaging/stc-iptables.spec b/packaging/stc-iptables.spec index b9139e2..031151a 100644 --- a/packaging/stc-iptables.spec +++ b/packaging/stc-iptables.spec @@ -1,6 +1,6 @@ Name: stc-iptables Summary: STC(Smart Traffic Control) iptables -Version: 0.0.24 +Version: 0.0.25 Release: 0 Group: Network & Connectivity/Other License: GPL-2.0 and Apache-2.0 diff --git a/src/helper/helper-config.c b/src/helper/helper-config.c index 26801e8..a3df39c 100755 --- a/src/helper/helper-config.c +++ b/src/helper/helper-config.c @@ -96,6 +96,6 @@ void helper_config_init(void) if (!keyfile) keyfile = g_key_file_new(); - g_key_file_set_integer(keyfile, path, INFO_LOGMODE, 0); + g_key_file_set_integer(keyfile, path, INFO_LOGMODE, 1); __save_config_file(keyfile, path); } diff --git a/src/helper/helper-log.c b/src/helper/helper-log.c index 864a432..6f629bf 100755 --- a/src/helper/helper-log.c +++ b/src/helper/helper-log.c @@ -26,10 +26,10 @@ #define LOG_FILE_PATH "/opt/usr/data/network/stc-iptables.log" #define MAX_LOG_SIZE 1 * 1024 * 1024 -#define MAX_LOG_COUNT 1 +#define MAX_LOG_COUNT 3 static FILE *g_log_file = NULL; -static int g_log_mode = 0; +static int g_log_mode = 1; //LCOV_EXCL_START static void __stc_iptables_log_update_file_revision(int rev) @@ -75,16 +75,15 @@ static void __stc_iptables_log_make_backup(void) static void __stc_iptables_log_get_local_time(char *strtime, const int size) { - time_t buf; + struct timeval tv; struct tm *local_ptm; - struct tm result = {0, }; + char buf[32]; - time(&buf); - buf = time(NULL); - local_ptm = localtime_r(&buf, &result); + gettimeofday(&tv, NULL); + local_ptm = localtime(&tv.tv_sec); - if (local_ptm) - strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm); + strftime(buf, sizeof(buf), "%m/%d %H:%M:%S", local_ptm); + snprintf(strtime, size, "%s.%03ld", buf, tv.tv_usec / 1000); } void helper_log_set_mode(int mode) @@ -109,10 +108,15 @@ void helper_log(const char *format, ...) if (g_log_file == NULL) return; + if (fstat(fileno(g_log_file), &buf) < 0) { + fclose(g_log_file); + g_log_file = NULL; + return; + } + va_start(ap, format); - if (fstat(fileno(g_log_file), &buf) == 0) - log_size = buf.st_size; + log_size = buf.st_size; if (log_size >= MAX_LOG_SIZE) { //LCOV_EXCL_START