The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions
exfile.c File Reference
#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
#include <freeradius-devel/server/exfile.h>
#include <freeradius-devel/server/trigger.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/file.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/perm.h>
#include <freeradius-devel/util/syserror.h>
#include <sys/stat.h>
#include <fcntl.h>
+ Include dependency graph for exfile.c:

Go to the source code of this file.

Data Structures

struct  exfile_entry_t
 
struct  exfile_s
 

Macros

#define MAX_TRY_LOCK   4
 How many times we attempt to acquire a lock. More...
 

Functions

static int _exfile_free (exfile_t *ef)
 
static void exfile_cleanup_entry (exfile_t *ef, exfile_entry_t *entry)
 
int exfile_close (exfile_t *ef, int fd)
 Close the log file. More...
 
static int exfile_close_lock (exfile_t *ef, int fd)
 
void exfile_enable_triggers (exfile_t *ef, CONF_SECTION *conf, char const *trigger_prefix, fr_pair_list_t *trigger_args)
 Enable triggers for an exfiles handle. More...
 
exfile_texfile_init (TALLOC_CTX *ctx, uint32_t max_entries, fr_time_delta_t max_idle, bool locking)
 Initialize a way for multiple threads to log to one or more files. More...
 
int exfile_open (exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
 Open a new log file, or maybe an existing one. More...
 
static int exfile_open_lock (exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
 
static int exfile_open_mkdir (exfile_t *ef, char const *filename, mode_t permissions)
 
static void exfile_trigger_exec (exfile_t *ef, exfile_entry_t *entry, char const *name_suffix)
 Send an exfile trigger. More...
 

Data Structure Documentation

◆ exfile_entry_t

struct exfile_entry_t

Definition at line 39 of file exfile.c.

+ Collaboration diagram for exfile_entry_t:
Data Fields
int fd File descriptor associated with an entry.
char * filename Filename.
uint32_t hash Hash for cheap comparison.
fr_time_t last_used Last time the entry was used.
dev_t st_dev device inode
ino_t st_ino inode number

◆ exfile_s

struct exfile_s

Definition at line 49 of file exfile.c.

+ Collaboration diagram for exfile_s:
Data Fields
CONF_SECTION * conf Conf section to search for triggers.
exfile_entry_t * entries
fr_time_t last_cleaned
bool locking
uint32_t max_entries How many file descriptors we keep track of.
fr_time_delta_t max_idle Maximum idle time for a descriptor.
pthread_mutex_t mutex
fr_pair_list_t trigger_args Arguments to pass to trigger.
char const * trigger_prefix Trigger path in the global trigger section.

Macro Definition Documentation

◆ MAX_TRY_LOCK

#define MAX_TRY_LOCK   4

How many times we attempt to acquire a lock.

before giving up.

Definition at line 62 of file exfile.c.

Function Documentation

◆ _exfile_free()

static int _exfile_free ( exfile_t ef)
static

Definition at line 120 of file exfile.c.

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

◆ exfile_cleanup_entry()

static void exfile_cleanup_entry ( exfile_t ef,
exfile_entry_t entry 
)
static

Definition at line 101 of file exfile.c.

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

◆ exfile_close()

int exfile_close ( exfile_t ef,
int  fd 
)

Close the log file.

Really just return it to the pool.

When multithreaded, the FD is locked via a mutex. This way we're sure that no other thread is writing to the file. This function will unlock the mutex, so that other threads can write to the file.

Parameters
efThe logfile context returned from exfile_init.
fdthe FD to close (i.e. return to the pool).
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 562 of file exfile.c.

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

◆ exfile_close_lock()

static int exfile_close_lock ( exfile_t ef,
int  fd 
)
static

Definition at line 526 of file exfile.c.

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

◆ exfile_enable_triggers()

void exfile_enable_triggers ( exfile_t ef,
CONF_SECTION conf,
char const *  trigger_prefix,
fr_pair_list_t trigger_args 
)

Enable triggers for an exfiles handle.

Parameters
[in]efto enable triggers for.
[in]confsection to search for triggers in.
[in]trigger_prefixprefix to prepend to all trigger names. Usually a path to the module's trigger configuration .e.g.
modules.<name>.file 
<trigger name> 
is appended to form the complete path.
[in]trigger_argsto make available in any triggers executed by the exfile api. Exfile-File is automatically added to this list.

Definition at line 196 of file exfile.c.

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

◆ exfile_init()

exfile_t* exfile_init ( TALLOC_CTX *  ctx,
uint32_t  max_entries,
fr_time_delta_t  max_idle,
bool  locking 
)

Initialize a way for multiple threads to log to one or more files.

Parameters
ctxThe talloc context
max_entriesMax file descriptors to cache, and manage locks for.
max_idleMaximum time a file descriptor can be idle before it's closed.
lockingwhether or not to lock the files.
Returns
  • new context.
  • NULL on error.

Definition at line 148 of file exfile.c.

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

◆ exfile_open()

int exfile_open ( exfile_t ef,
char const *  filename,
mode_t  permissions,
off_t offset 
)

Open a new log file, or maybe an existing one.

When multithreaded, the FD is locked via a mutex. This way we're sure that no other thread is writing to the file.

Parameters
efThe logfile context returned from exfile_init().
filenamethe file to open.
permissionsto use.
offsetOptional pointer to store offset in when seeking the end of file.
Returns
  • FD used to write to the file.
  • -1 on failure.

Definition at line 506 of file exfile.c.

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

◆ exfile_open_lock()

static int exfile_open_lock ( exfile_t ef,
char const *  filename,
mode_t  permissions,
off_t offset 
)
static

Definition at line 269 of file exfile.c.

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

◆ exfile_open_mkdir()

static int exfile_open_mkdir ( exfile_t ef,
char const *  filename,
mode_t  permissions 
)
static

Definition at line 215 of file exfile.c.

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

◆ exfile_trigger_exec()

static void exfile_trigger_exec ( exfile_t ef,
exfile_entry_t entry,
char const *  name_suffix 
)
inlinestatic

Send an exfile trigger.

Parameters
[in]efto send trigger for.
[in]entryfor the file that the event occurred on.
[in]name_suffixtrigger name suffix.

Definition at line 70 of file exfile.c.

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