All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
exfile.c File Reference
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/exfile.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_t
 

Macros

#define MAX_TRY_LOCK   4
 How many times we attempt to acquire a lock. More...
 
#define PTHREAD_MUTEX_LOCK(_x)
 
#define PTHREAD_MUTEX_UNLOCK(_x)
 

Typedefs

typedef struct exfile_entry_t exfile_entry_t
 

Functions

static int _exfile_free (exfile_t *ef)
 
int exfile_close (exfile_t *ef, int fd)
 Close the log file. More...
 
exfile_texfile_init (TALLOC_CTX *ctx, uint32_t max_entries, uint32_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, bool append)
 Open a new log file, or maybe an existing one. More...
 
int exfile_unlock (exfile_t *ef, int fd)
 

Data Structure Documentation

struct exfile_entry_t

Definition at line 32 of file exfile.c.

Data Fields
int dup
int fd File descriptor associated with an entry.
char * filename Filename.
uint32_t hash Hash for cheap comparison.
time_t last_used Last time the entry was used.
struct exfile_t

Definition at line 41 of file exfile.c.

+ Collaboration diagram for exfile_t:
Data Fields
exfile_entry_t * entries
bool locking
uint32_t max_entries How many file descriptors we keep track of.
uint32_t max_idle Maximum idle time for a descriptor.

Macro Definition Documentation

#define MAX_TRY_LOCK   4

How many times we attempt to acquire a lock.

before giving up.

Definition at line 65 of file exfile.c.

#define PTHREAD_MUTEX_LOCK (   _x)

Definition at line 61 of file exfile.c.

#define PTHREAD_MUTEX_UNLOCK (   _x)

Definition at line 62 of file exfile.c.

Typedef Documentation

Function Documentation

static int _exfile_free ( exfile_t ef)
static

Definition at line 68 of file exfile.c.

+ Here is the caller graph for this function:

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 356 of file exfile.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

exfile_t* exfile_init ( TALLOC_CTX *  ctx,
uint32_t  max_entries,
uint32_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 100 of file exfile.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int exfile_open ( exfile_t ef,
char const *  filename,
mode_t  permissions,
bool  append 
)

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.
appendIf true seek to the end of the file.
Returns
  • FD used to write to the file.
  • -1 on failure.

Definition at line 142 of file exfile.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int exfile_unlock ( exfile_t ef,
int  fd 
)

Definition at line 382 of file exfile.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: