diff --git a/src/util-profiling-locks.c b/src/util-profiling-locks.c index 8d31410d62..b88e27dd26 100644 --- a/src/util-profiling-locks.c +++ b/src/util-profiling-locks.c @@ -38,7 +38,7 @@ __thread int record_locks = 0; int profiling_locks_enabled = 0; int profiling_locks_output_to_file = 0; char *profiling_locks_file_name = NULL; -char *profiling_locks_file_mode = NULL; +char *profiling_locks_file_mode = "a"; typedef struct LockRecord_ { char *file; // hash @@ -147,11 +147,7 @@ void SCProfilingListLocks(void) { FILE *fp = NULL; if (profiling_locks_output_to_file == 1) { - if (strcasecmp(profiling_locks_file_mode, "yes") == 0) { - fp = fopen(profiling_locks_file_name, "a"); - } else { - fp = fopen(profiling_locks_file_name, "w"); - } + fp = fopen(profiling_locks_file_name, profiling_locks_file_mode); if (fp == NULL) { SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", diff --git a/src/util-profiling-rules.c b/src/util-profiling-rules.c index 20cd4a6a42..7afa52e1fd 100644 --- a/src/util-profiling-rules.c +++ b/src/util-profiling-rules.c @@ -87,7 +87,7 @@ static SCProfileData rules_profile_data[0xffff]; static pthread_mutex_t rules_profile_data_m; int profiling_rules_enabled = 0; static char *profiling_file_name = ""; -static const char *profiling_file_mode = ""; +static const char *profiling_file_mode = "a"; /** * Sort orders for dumping profiled rules. @@ -173,9 +173,12 @@ void SCProfilingRulesGlobalInit(void) { profiling_file_name = SCMalloc(PATH_MAX); snprintf(profiling_file_name, PATH_MAX, "%s/%s", log_dir, filename); - profiling_file_mode = ConfNodeLookupChildValue(conf, "append"); - if (profiling_file_mode == NULL) - profiling_file_mode = DEFAULT_LOG_MODE_APPEND; + const char *v = ConfNodeLookupChildValue(conf, "append"); + if (v == NULL || ConfValIsTrue(v)) { + profiling_file_mode = "a"; + } else { + profiling_file_mode = "w"; + } profiling_output_to_file = 1; } @@ -272,11 +275,7 @@ SCProfilingRuleDump(SCProfileDetectCtx *rules_ctx) struct timeval tval; struct tm *tms; if (profiling_output_to_file == 1) { - if (ConfValIsTrue(profiling_file_mode)) { - fp = fopen(profiling_file_name, "a"); - } else { - fp = fopen(profiling_file_name, "w"); - } + fp = fopen(profiling_file_name, profiling_file_mode); if (fp == NULL) { SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", profiling_file_name, diff --git a/src/util-profiling.c b/src/util-profiling.c index 92ef3f2387..135671d6fe 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -94,7 +94,7 @@ int profiling_packets_output_to_file = 0; char *profiling_file_name; char *profiling_packets_file_name; char *profiling_csv_file_name; -const char *profiling_packets_file_mode; +const char *profiling_packets_file_mode = "a"; /** * Used as a check so we don't double enter a profiling run. @@ -143,9 +143,12 @@ SCProfilingInit(void) profiling_packets_file_name = SCMalloc(PATH_MAX); snprintf(profiling_packets_file_name, PATH_MAX, "%s/%s", log_dir, filename); - profiling_packets_file_mode = ConfNodeLookupChildValue(conf, "append"); - if (profiling_packets_file_mode == NULL) - profiling_packets_file_mode = DEFAULT_LOG_MODE_APPEND; + const char *v = ConfNodeLookupChildValue(conf, "append"); + if (v == NULL || ConfValIsTrue(v)) { + profiling_packets_file_mode = "a"; + } else { + profiling_packets_file_mode = "w"; + } profiling_packets_output_to_file = 1; } @@ -214,9 +217,12 @@ SCProfilingInit(void) profiling_locks_file_name = SCMalloc(PATH_MAX); snprintf(profiling_locks_file_name, PATH_MAX, "%s/%s", log_dir, filename); - profiling_locks_file_mode = (char *)ConfNodeLookupChildValue(conf, "append"); - if (profiling_locks_file_mode == NULL) - profiling_locks_file_mode = DEFAULT_LOG_MODE_APPEND; + const char *v = ConfNodeLookupChildValue(conf, "append"); + if (v == NULL || ConfValIsTrue(v)) { + profiling_locks_file_mode = "a"; + } else { + profiling_locks_file_mode = "w"; + } profiling_locks_output_to_file = 1; } @@ -267,11 +273,7 @@ void SCProfilingDumpPacketStats(void) { return; if (profiling_packets_output_to_file == 1) { - if (strcasecmp(profiling_packets_file_mode, "yes") == 0) { - fp = fopen(profiling_packets_file_name, "a"); - } else { - fp = fopen(profiling_packets_file_name, "w"); - } + fp = fopen(profiling_packets_file_name, profiling_packets_file_mode); if (fp == NULL) { SCLogError(SC_ERR_FOPEN, "failed to open %s: %s",