Enable logging by default 00/232000/1 accepted/tizen/unified/20200428.001329 submit/tizen/20200427.103226
authorhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 27 Apr 2020 08:39:09 +0000 (17:39 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 27 Apr 2020 08:39:12 +0000 (17:39 +0900)
Change-Id: Iedcdd47d199514ee3aa3c84147aa96ed38a52298
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
packaging/stc-iptables.spec
src/helper/helper-config.c
src/helper/helper-log.c

index b9139e28685075dea06636dddd3054d7cda587ea..031151af2e11b6788e2750a9d801b2f5cbdf966a 100644 (file)
@@ -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
index 26801e82bed0d91b7293704ede96f1010bb27cbc..a3df39cfceeac24a519277397658b691b2bc6d4b 100755 (executable)
@@ -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);
 }
index 864a432b411798f261fdae6e3ffc3171072fe5b8..6f629bfb68baea63fcdce0c3f98ee23d071e8ec2 100755 (executable)
 
 #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