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);
}
#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)
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)
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