Merge in SNORT/snort3 from ~SATHIRKA/snort3:appid_stats_fatalerr_fix to master
Squashed commit of the following:
commit
c1e4352680234f9dcd5e7a2a9747798fe45983d7
Author: Sreeja Athirkandathil Narayanan <sathirka@cisco.com>
Date: Mon Jan 29 14:39:14 2024 -0500
appid: log error message instead of fatal error if appid stats logfile is not accessible
* Returns: file handle
*
***************************************************************************/
-FILE* OpenAlertFile(const char* filearg)
+FILE* OpenAlertFile(const char* filearg, bool is_critical)
{
FILE* file;
if ((file = fopen(filename, "a")) == nullptr)
{
- FatalError("OpenAlertFile() => fopen() alert file %s: %s\n",
- filename, get_error(errno));
+ if (is_critical)
+ FatalError("OpenAlertFile() => fopen() alert file %s: %s\n", filename, get_error(errno));
+ else
+ ErrorMessage("OpenAlertFile() => fopen() alert file %s: %s\n", filename, get_error(errno));
}
else
setvbuf(file, (char*)nullptr, _IOLBF, (size_t)0);
SO_PUBLIC void CreateTCPFlagString(const tcp::TCPHdr* const, char*);
}
-FILE* OpenAlertFile(const char*);
+FILE* OpenAlertFile(const char*, bool is_critical=true);
int RollAlertFile(const char*);
void OpenLogger();
* TextLog_Open/Close: open/close associated log file
*-------------------------------------------------------------------
*/
-static FILE* TextLog_Open(const char* name)
+static FILE* TextLog_Open(const char* name, bool is_critical=true)
{
if ( name && !strcasecmp(name, "stdout") )
{
#endif
}
- return OpenAlertFile(name);
+ return OpenAlertFile(name, is_critical);
}
static void TextLog_Close(FILE* file)
*-------------------------------------------------------------------
*/
TextLog* TextLog_Init(
- const char* name, unsigned int maxBuf, size_t maxFile)
+ const char* name, unsigned int maxBuf, size_t maxFile, bool is_critical)
{
TextLog* txt;
txt = (TextLog*)snort_alloc(sizeof(TextLog)+maxBuf);
txt->name = name ? snort_strdup(name) : nullptr;
- txt->file = TextLog_Open(txt->name);
+ txt->file = TextLog_Open(txt->name, is_critical);
+ if (!txt->file)
+ {
+ if ( txt->name )
+ snort_free(txt->name);
+ snort_free(txt);
+ return nullptr;
+ }
txt->size = TextLog_Size(txt->file);
txt->last = time(nullptr);
txt->maxFile = maxFile;
namespace snort
{
SO_PUBLIC TextLog* TextLog_Init(
- const char* name, unsigned int maxBuf = 0, size_t maxFile = 0);
+ const char* name, unsigned int maxBuf = 0, size_t maxFile = 0, bool is_critical=true);
SO_PUBLIC void TextLog_Term(TextLog*);
SO_PUBLIC bool TextLog_Putc(TextLog* const, char);
void AppIdStatistics::open_stats_log_file()
{
- log = TextLog_Init(appid_stats_filename, 4096, roll_size);
+ log = TextLog_Init(appid_stats_filename, 4096, roll_size, false);
+ if (!log)
+ log_err = true;
}
void AppIdStatistics::dump_statistics()
{
- if ( !log_buckets )
+ if ( !log_buckets or log_err )
return;
if ( !log )
while ((bucket = (struct StatsBucket*)sflist_remove_head(log_buckets)) != nullptr)
{
+ if (log_err)
+ {
+ delete bucket;
+ continue;
+ }
if ( bucket->app_record_cnt )
{
for (auto& it : bucket->apps_tree)
time_t bucket_interval = 0;
time_t bucket_end = 0;
size_t roll_size = 0;
+ bool log_err = false;
};
#endif