suricata
util-logopenfile.c File Reference
#include "suricata-common.h"
#include "util-logopenfile.h"
#include "suricata.h"
#include "conf.h"
#include "output.h"
#include "util-byte.h"
#include "util-conf.h"
#include "util-path.h"
#include "util-misc.h"
#include "util-time.h"
#include "log-maintenance.h"
Include dependency graph for util-logopenfile.c:

Go to the source code of this file.

Macros

#define LOGFILE_NAME_MAX   255
 

Functions

bool SCLogOpenThreadedFile (const char *log_path, const char *append, LogFileCtx *parent_ctx)
 
int SCConfLogOpenGeneric (SCConfNode *conf, LogFileCtx *log_ctx, const char *default_filename, int rotate)
 open a generic output "log file", which may be a regular file or a socket More...
 
int SCConfLogReopen (LogFileCtx *log_ctx)
 Reopen a regular log file with the side-affect of truncating it. More...
 
LogFileCtxLogFileNewCtx (void)
 LogFileNewCtx() Get a new LogFileCtx. More...
 
LogFileCtxLogFileEnsureExists (ThreadId thread_id, LogFileCtx *parent_ctx)
 LogFileEnsureExists() Ensure a log file context for the thread exists. More...
 
int LogFileFreeCtx (LogFileCtx *lf_ctx)
 LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory) More...
 
void LogFileFlush (LogFileCtx *file_ctx)
 
void LogFileRegister (LogFileCtx *ctx)
 Register a LogFileCtx for maintenance operations. More...
 
void LogFileUnregister (LogFileCtx *ctx)
 Unregister a LogFileCtx from maintenance operations. More...
 
void LogFileFlushAll (void)
 Flush all registered LogFileCtx instances. More...
 
void LogFileRotateAll (void)
 Check rotation for all registered LogFileCtx instances. More...
 
int LogFileWrite (LogFileCtx *file_ctx, MemBuffer *buffer)
 

Detailed Description

Author
Mike Pomraning mpomr.nosp@m.anin.nosp@m.g@qua.nosp@m.lys..nosp@m.com

File-like output for logging: regular files and sockets.

Definition in file util-logopenfile.c.

Macro Definition Documentation

◆ LOGFILE_NAME_MAX

#define LOGFILE_NAME_MAX   255

Definition at line 50 of file util-logopenfile.c.

Function Documentation

◆ LogFileEnsureExists()

LogFileCtx* LogFileEnsureExists ( ThreadId  thread_id,
LogFileCtx parent_ctx 
)

LogFileEnsureExists() Ensure a log file context for the thread exists.

Parameters
parent_ctx
Return values
LogFileCtx* pointer if successful; NULL otherwise

Definition at line 787 of file util-logopenfile.c.

References LogThreadedFileCtx_::mutex, SCMutexLock, LogFileCtx_::threaded, and LogFileCtx_::threads.

Referenced by CreateEveThreadCtx(), and JsonLogThreadInit().

Here is the caller graph for this function:

◆ LogFileFlush()

void LogFileFlush ( LogFileCtx file_ctx)

◆ LogFileFlushAll()

void LogFileFlushAll ( void  )

Flush all registered LogFileCtx instances.

Called by the maintenance thread to flush all active file-based loggers.

Definition at line 1085 of file util-logopenfile.c.

References SCMutexLock.

◆ LogFileFreeCtx()

◆ LogFileNewCtx()

LogFileCtx* LogFileNewCtx ( void  )

LogFileNewCtx() Get a new LogFileCtx.

Return values
LogFileCtx* pointer if successful, NULL if error

Definition at line 735 of file util-logopenfile.c.

References SCCalloc, and LogFileCtx_::Write.

Referenced by AlertFastLogInitCtx(), LogTcpDataLogInitCtx(), and OutputJsonInitCtx().

Here is the caller graph for this function:

◆ LogFileRegister()

void LogFileRegister ( LogFileCtx ctx)

Register a LogFileCtx for maintenance operations.

Adds a LogFileCtx to the global log file list so the heartbeat thread can perform flush and rotation on it.

Parameters
ctxThe LogFileCtx to register (must be LOGFILE_TYPE_FILE)

Definition at line 1036 of file util-logopenfile.c.

References LogFileEntry_::ctx, ctx, LOGFILE_TYPE_FILE, SCLogError, SCMalloc, and SCMutexLock.

◆ LogFileRotateAll()

void LogFileRotateAll ( void  )

Check rotation for all registered LogFileCtx instances.

Called by the maintenance thread to trigger rotation checks on all registered log contexts during zero-traffic periods.

Definition at line 1103 of file util-logopenfile.c.

References SCMutexLock.

◆ LogFileUnregister()

void LogFileUnregister ( LogFileCtx ctx)

Unregister a LogFileCtx from maintenance operations.

Removes a LogFileCtx from the global log file list.

Parameters
ctxThe LogFileCtx to unregister

Definition at line 1062 of file util-logopenfile.c.

References ctx, and SCMutexLock.

Referenced by LogFileFreeCtx().

Here is the caller graph for this function:

◆ LogFileWrite()

◆ SCConfLogOpenGeneric()

int SCConfLogOpenGeneric ( SCConfNode conf,
LogFileCtx log_ctx,
const char *  default_filename,
int  rotate 
)

open a generic output "log file", which may be a regular file or a socket

Parameters
confConfNode structure for the output section in question
log_ctxLog file context allocated by caller
default_filenameDefault name of file to open, if not specified in ConfNode
rotateRegister the file for rotation in HUP.
Return values
0on success
-1on error

Definition at line 499 of file util-logopenfile.c.

References LogFileCtx_::buffer_size, LogFileCtx_::compress_ipv6, DEFAULT_LOG_FILETYPE, DEFAULT_LOG_MODE_APPEND, FatalError, LogFileCtx_::filemode, LogFileCtx_::flags, LogFileCtx_::fp, LogFileCtx_::is_regular, LogFileCtx_::is_sock, JSON_ESCAPE_SLASH, LogFileCtx_::json_flags, LOGFILE_EVE_BUFFER_SIZE, LOGFILE_ROTATE_INTERVAL, ParseSizeStringU32(), PathIsAbsolute(), LogFileCtx_::rotate_interval, LogFileCtx_::rotate_time, SCConfigGetLogDirectory(), SCConfNodeLookupChild(), SCConfNodeLookupChildValue(), SCConfValIsFalse(), SCConfValIsTrue(), SCGetSecondsUntil(), SCLogDebug, SCLogError, SCParseTimeSizeString(), LogFileCtx_::sock_type, StringParseUint32(), and LogFileCtx_::threaded.

Referenced by AlertFastLogInitCtx(), and LogTcpDataLogInitCtx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCConfLogReopen()

int SCConfLogReopen ( LogFileCtx log_ctx)

Reopen a regular log file with the side-affect of truncating it.

This is useful to clear the log file and start a new one, or to re-open the file after its been moved by something external (eg. logrotate).

Definition at line 704 of file util-logopenfile.c.

References LogFileCtx_::filename, LogFileCtx_::fp, LogFileCtx_::is_regular, SCLogDebug, and SCLogWarning.

◆ SCLogOpenThreadedFile()

bool SCLogOpenThreadedFile ( const char *  log_path,
const char *  append,
LogFileCtx parent_ctx 
)

Definition at line 394 of file util-logopenfile.c.

References HashTableInit(), LogThreadedFileCtx_::ht, SCCalloc, SCLogError, and LogFileCtx_::threads.

Here is the call graph for this function: