Skip to content

Commit

Permalink
profiling: allow absolute paths
Browse files Browse the repository at this point in the history
Ticket OISF#6490.

(cherry picked from commit f4c348b)
  • Loading branch information
victorjulien authored and jlucovsky committed Aug 18, 2024
1 parent d72ec89 commit cf0018f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
13 changes: 8 additions & 5 deletions src/util-profiling-keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "detect-engine.h"
#include "tm-threads.h"
#include "util-conf.h"
#include "util-path.h"
#include "util-time.h"

/**
Expand Down Expand Up @@ -67,11 +68,13 @@ void SCProfilingKeywordsGlobalInit(void)
profiling_keyword_enabled = 1;
const char *filename = ConfNodeLookupChildValue(conf, "filename");
if (filename != NULL) {
const char *log_dir;
log_dir = ConfigGetLogDirectory();

snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s",
log_dir, filename);
if (PathIsAbsolute(filename)) {
strlcpy(profiling_file_name, filename, sizeof(profiling_file_name));
} else {
const char *log_dir = ConfigGetLogDirectory();
snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir,
filename);
}

const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
Expand Down
13 changes: 8 additions & 5 deletions src/util-profiling-prefilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#ifdef PROFILING
#include "detect-engine-prefilter.h"
#include "util-conf.h"
#include "util-path.h"
#include "util-time.h"

typedef struct SCProfilePrefilterData_ {
Expand Down Expand Up @@ -67,11 +68,13 @@ void SCProfilingPrefilterGlobalInit(void)
profiling_prefilter_enabled = 1;
const char *filename = ConfNodeLookupChildValue(conf, "filename");
if (filename != NULL) {
const char *log_dir;
log_dir = ConfigGetLogDirectory();

snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s",
log_dir, filename);
if (PathIsAbsolute(filename)) {
strlcpy(profiling_file_name, filename, sizeof(profiling_file_name));
} else {
const char *log_dir = ConfigGetLogDirectory();
snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir,
filename);
}

const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
Expand Down
13 changes: 8 additions & 5 deletions src/util-profiling-rulegroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#ifdef PROFILING
#include "util-conf.h"
#include "util-path.h"
#include "util-time.h"

/**
Expand Down Expand Up @@ -70,11 +71,13 @@ void SCProfilingSghsGlobalInit(void)
profiling_sghs_enabled = 1;
const char *filename = ConfNodeLookupChildValue(conf, "filename");
if (filename != NULL) {
const char *log_dir;
log_dir = ConfigGetLogDirectory();

snprintf(profiling_file_name, sizeof(profiling_file_name),
"%s/%s", log_dir, filename);
if (PathIsAbsolute(filename)) {
strlcpy(profiling_file_name, filename, sizeof(profiling_file_name));
} else {
const char *log_dir = ConfigGetLogDirectory();
snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir,
filename);
}

const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
Expand Down
14 changes: 8 additions & 6 deletions src/util-profiling-rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "util-byte.h"
#include "util-conf.h"
#include "util-path.h"
#include "util-time.h"

#ifdef PROFILE_RULES
Expand Down Expand Up @@ -139,12 +140,13 @@ void SCProfilingRulesGlobalInit(void)
}
const char *filename = ConfNodeLookupChildValue(conf, "filename");
if (filename != NULL) {

const char *log_dir;
log_dir = ConfigGetLogDirectory();

snprintf(profiling_file_name, sizeof(profiling_file_name),
"%s/%s", log_dir, filename);
if (PathIsAbsolute(filename)) {
strlcpy(profiling_file_name, filename, sizeof(profiling_file_name));
} else {
const char *log_dir = ConfigGetLogDirectory();
snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir,
filename);
}

const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
Expand Down
32 changes: 21 additions & 11 deletions src/util-profiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "util-byte.h"
#include "util-profiling-locks.h"
#include "util-conf.h"
#include "util-path.h"

#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
Expand Down Expand Up @@ -172,11 +173,14 @@ SCProfilingInit(void)

const char *filename = ConfNodeLookupChildValue(conf, "filename");
if (filename != NULL) {
const char *log_dir;
log_dir = ConfigGetLogDirectory();

snprintf(profiling_packets_file_name, sizeof(profiling_packets_file_name),
"%s/%s", log_dir, filename);
if (PathIsAbsolute(filename)) {
strlcpy(profiling_packets_file_name, filename,
sizeof(profiling_packets_file_name));
} else {
const char *log_dir = ConfigGetLogDirectory();
snprintf(profiling_packets_file_name, sizeof(profiling_packets_file_name),
"%s/%s", log_dir, filename);
}

const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
Expand All @@ -196,14 +200,20 @@ SCProfilingInit(void)
if (filename == NULL) {
filename = "packet_profile.csv";
}
if (PathIsAbsolute(filename)) {
profiling_csv_file_name = SCStrdup(filename);
if (unlikely(profiling_csv_file_name == NULL)) {
FatalError("out of memory");
}
} else {
profiling_csv_file_name = SCMalloc(PATH_MAX);
if (unlikely(profiling_csv_file_name == NULL)) {
FatalError("out of memory");
}

const char *log_dir = ConfigGetLogDirectory();

profiling_csv_file_name = SCMalloc(PATH_MAX);
if (unlikely(profiling_csv_file_name == NULL)) {
FatalError("out of memory");
const char *log_dir = ConfigGetLogDirectory();
snprintf(profiling_csv_file_name, PATH_MAX, "%s/%s", log_dir, filename);
}
snprintf(profiling_csv_file_name, PATH_MAX, "%s/%s", log_dir, filename);

packet_profile_csv_fp = fopen(profiling_csv_file_name, "w");
if (packet_profile_csv_fp == NULL) {
Expand Down

0 comments on commit cf0018f

Please sign in to comment.