The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions | Variables
strerror.c File Reference

Support functions to allow libraries to provide errors to their callers. More...

#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/atexit.h>
#include <stdbool.h>
+ Include dependency graph for strerror.c:

Go to the source code of this file.

Data Structures

struct  fr_log_buffer_t
 Holds data used by the logging stack. More...
 
struct  fr_log_entry_s
 

Macros

#define FR_STRERROR_BUFSIZE   (2048)
 

Typedefs

typedef struct fr_log_entry_s fr_log_entry_t
 

Functions

static int _fr_logging_free (void *arg)
 
void _fr_strerror_const (char const *file, int line, char const *msg)
 Log to thread local error buffer. More...
 
void _fr_strerror_const_push (char const *file, int line, char const *msg)
 Add a message to an existing stack of messages at the tail. More...
 
void _fr_strerror_const_push_head (char const *file, int line, char const *msg)
 Add a message to an existing stack of messages at the head. More...
 
void _fr_strerror_marker_vprintf (char const *file, int line, char const *subject, size_t offset, char const *fmt, va_list ap)
 Add an error marker to an existing stack of messages. More...
 
void _fr_strerror_marker_vprintf_push (char const *file, int line, char const *subject, size_t offset, char const *fmt, va_list ap)
 Add an error marker to an existing stack of messages at the tail. More...
 
void _fr_strerror_marker_vprintf_push_head (char const *file, int line, char const *subject, size_t offset, char const *fmt, va_list ap)
 Add an error marker to an existing stack of messages at the head. More...
 
void _fr_strerror_vprintf (char const *file, int line, char const *fmt, va_list ap)
 Log to thread local error buffer. More...
 
void _fr_strerror_vprintf_push (char const *file, int line, char const *fmt, va_list ap)
 Add a message to an existing stack of messages at the tail. More...
 
void _fr_strerror_vprintf_push_head (char const *file, int line, char const *fmt, va_list ap)
 Add a message to an existing stack of messages at the head. More...
 
void fr_perror (char const *fmt,...)
 Print the current error to stderr with a prefix. More...
 
char const * fr_perror_to_str (char const *line_sep, char const *fmt,...)
 Print the stack of string buffers to a thread local buffer. More...
 
char const * fr_strerror (void)
 Get the last library error. More...
 
void fr_strerror_clear (void)
 Clears all pending messages from the talloc pools. More...
 
static fr_log_buffer_tfr_strerror_init (void)
 Initialise thread local storage. More...
 
char const * fr_strerror_marker (char const **subject, size_t *offset)
 Get the last library error marker. More...
 
char const * fr_strerror_marker_peek (char const **subject, size_t *offset)
 Get the last library error marker. More...
 
char const * fr_strerror_marker_pop (char const **subject, size_t *offset)
 Pop the last library error with marker information. More...
 
char const * fr_strerror_peek (void)
 Get the last library error. More...
 
char const * fr_strerror_pop (void)
 Pop the last library error. More...
 
static TALLOC_CTX * pool_alt (fr_log_buffer_t *buffer)
 
static void pool_alt_free_children (fr_log_buffer_t *buffer)
 
static fr_log_entry_tstrerror_const (char const *file, int line, char const *msg)
 Create an entry in the thread local logging stack using a const string, clearing all other entries. More...
 
static fr_log_entry_tstrerror_const_push (char const *file, int line, fr_log_buffer_t *buffer, char const *msg)
 Add a message to an existing stack of messages. More...
 
static fr_log_entry_tstrerror_vprintf (char const *file, int line, char const *fmt, va_list ap)
 Create an entry in the thread local logging stack, clearing all other entries. More...
 
static fr_log_entry_tstrerror_vprintf_push (char const *file, int line, fr_log_buffer_t *buffer, char const *fmt, va_list ap)
 Add a message to an existing stack of messages. More...
 

Variables

static _Thread_local fr_log_buffer_tfr_strerror_buffer
 
static _Thread_local bool logging_stop
 Due to ordering issues we may get errors being logged from within other thread local destructors which cause a crash on exit if the logging buffer has already been freed. More...
 

Detailed Description

Support functions to allow libraries to provide errors to their callers.

Definition in file strerror.c.


Data Structure Documentation

◆ fr_log_buffer_t

struct fr_log_buffer_t

Holds data used by the logging stack.

pool_a and pool_b allow fr_strerror and fr_strerror_pop during a call to fr_strerror_printf or fr_strerror_printf_push.

Definition at line 51 of file strerror.c.

+ Collaboration diagram for fr_log_buffer_t:
Data Fields
fr_dlist_head_t entries
TALLOC_CTX * pool Current pool in use.
TALLOC_CTX * pool_a Pool to avoid memory allocations.
TALLOC_CTX * pool_b Pool to avoid memory allocations.

◆ fr_log_entry_s

struct fr_log_entry_s

Definition at line 35 of file strerror.c.

+ Collaboration diagram for fr_log_entry_s:
Data Fields
char const * file File where the error was created.
int line Line where the error occurred.
fr_dlist_t list
char const * msg Log message.
size_t offset Where to place the msg marker relative to the subject.
char const * subject Subject for error markers.

Macro Definition Documentation

◆ FR_STRERROR_BUFSIZE

#define FR_STRERROR_BUFSIZE   (2048)

Definition at line 32 of file strerror.c.

Typedef Documentation

◆ fr_log_entry_t

Definition at line 1 of file strerror.c.

Function Documentation

◆ _fr_logging_free()

static int _fr_logging_free ( void *  arg)
static

Definition at line 69 of file strerror.c.

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

◆ _fr_strerror_const()

void _fr_strerror_const ( char const *  file,
int  line,
char const *  msg 
)

Log to thread local error buffer.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 450 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_const_push()

void _fr_strerror_const_push ( char const *  file,
int  line,
char const *  msg 
)

Add a message to an existing stack of messages at the tail.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 508 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_const_push_head()

void _fr_strerror_const_push_head ( char const *  file,
int  line,
char const *  msg 
)

Add a message to an existing stack of messages at the head.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 531 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_vprintf()

void _fr_strerror_marker_vprintf ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
va_list  ap 
)

Add an error marker to an existing stack of messages.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]subjectto mark up.
[in]offsetPositive offset to show where the error should be positioned.
[in]fmtError string.
[in]apArguments for the error string.

Definition at line 320 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_vprintf_push()

void _fr_strerror_marker_vprintf_push ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
va_list  ap 
)

Add an error marker to an existing stack of messages at the tail.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]subjectto mark up.
[in]offsetPositive offset to show where the error should be positioned.
[in]fmtError string.
[in]apArguments for the error string.

Definition at line 348 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_vprintf_push_head()

void _fr_strerror_marker_vprintf_push_head ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
va_list  ap 
)

Add an error marker to an existing stack of messages at the head.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]subjectto mark up.
[in]offsetPositive offset to show where the error should be positioned.
[in]fmtError string.
[in]apArguments for the error string.

Definition at line 382 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_vprintf()

void _fr_strerror_vprintf ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)

Log to thread local error buffer.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]fmtprintf style format string. If NULL clears any existing messages.
[in]apArguments for the format string.

Definition at line 245 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_vprintf_push()

void _fr_strerror_vprintf_push ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)

Add a message to an existing stack of messages at the tail.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]fmtprintf style format string.
[in]apArguments for the format string.

Definition at line 263 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_vprintf_push_head()

void _fr_strerror_vprintf_push_head ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)

Add a message to an existing stack of messages at the head.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]fmtprintf style format string.
[in]apArguments for the format string.

Definition at line 290 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_perror()

void fr_perror ( char const *  fmt,
  ... 
)

Print the current error to stderr with a prefix.

Used by utility functions lacking their own logging infrastructure

Definition at line 733 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_perror_to_str()

char const* fr_perror_to_str ( char const *  line_sep,
char const *  fmt,
  ... 
)

Print the stack of string buffers to a thread local buffer.

Used by utility functions lacking their own logging infrastructure

Parameters
[in]line_septo insert between the log lines.
[in]fmtto prefix all log messages with.
Returns
  • A thread local string buffer containing the concatenated messages.

Definition at line 779 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror()

char const* fr_strerror ( void  )

Get the last library error.

Will only return the last library error once, after which it will return a zero length string. If there are additional messages on the log stack they will be discarded.

Returns
library error or zero length string.

Definition at line 554 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_clear()

void fr_strerror_clear ( void  )

Clears all pending messages from the talloc pools.

Definition at line 577 of file strerror.c.

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

◆ fr_strerror_init()

static fr_log_buffer_t* fr_strerror_init ( void  )
static

Initialise thread local storage.

Returns
fr_buffer_t containing log messages.

Definition at line 88 of file strerror.c.

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

◆ fr_strerror_marker()

char const* fr_strerror_marker ( char const **  subject,
size_t offset 
)

Get the last library error marker.

Parameters
[out]subjectThe subject string the error relates to.
[out]offsetWhere to place the marker.
Returns
  • NULL if there are no pending errors.
  • The error message if there was an error.

Definition at line 598 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_marker_peek()

char const* fr_strerror_marker_peek ( char const **  subject,
size_t offset 
)

Get the last library error marker.

Parameters
[out]subjectThe subject string the error relates to.
[out]offsetWhere to place the marker.
Returns
  • NULL if there are no pending errors.
  • The error message if there was an error.

Definition at line 651 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_marker_pop()

char const* fr_strerror_marker_pop ( char const **  subject,
size_t offset 
)

Pop the last library error with marker information.

Return the first message added to the error stack using fr_strerror_printf or fr_strerror_printf_push.

Returns
  • A library error.
  • NULL if no errors are pending.

Definition at line 708 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_peek()

char const* fr_strerror_peek ( void  )

Get the last library error.

Returns
library error or zero length string.

Definition at line 627 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_pop()

char const* fr_strerror_pop ( void  )

Pop the last library error.

Return the first message added to the error stack using fr_strerror_printf or fr_strerror_printf_push.

Note
Unlink fr_strerror() will return NULL if no messages are pending.
Returns
  • A library error.
  • NULL if no errors are pending.

Definition at line 681 of file strerror.c.

+ Here is the call graph for this function:

◆ pool_alt()

static TALLOC_CTX* pool_alt ( fr_log_buffer_t buffer)
inlinestatic

Definition at line 125 of file strerror.c.

+ Here is the caller graph for this function:

◆ pool_alt_free_children()

static void pool_alt_free_children ( fr_log_buffer_t buffer)
inlinestatic

Definition at line 134 of file strerror.c.

+ Here is the caller graph for this function:

◆ strerror_const()

static fr_log_entry_t* strerror_const ( char const *  file,
int  line,
char const *  msg 
)
inlinestatic

Create an entry in the thread local logging stack using a const string, clearing all other entries.

Definition at line 408 of file strerror.c.

+ Here is the call graph for this function:

◆ strerror_const_push()

static fr_log_entry_t* strerror_const_push ( char const *  file,
int  line,
fr_log_buffer_t buffer,
char const *  msg 
)
inlinestatic

Add a message to an existing stack of messages.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]bufferto add the message to.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 465 of file strerror.c.

+ Here is the call graph for this function:

◆ strerror_vprintf()

static fr_log_entry_t* strerror_vprintf ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)
static

Create an entry in the thread local logging stack, clearing all other entries.

Note
Can't be inlined.

Definition at line 149 of file strerror.c.

+ Here is the call graph for this function:

◆ strerror_vprintf_push()

static fr_log_entry_t* strerror_vprintf_push ( char const *  file,
int  line,
fr_log_buffer_t buffer,
char const *  fmt,
va_list  ap 
)
static

Add a message to an existing stack of messages.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]bufferThe log buffer to allocate memory from.
[in]fmtprintf style format string.
[in]apArguments for the error string.
Note
Can't be inline.

Definition at line 201 of file strerror.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_strerror_buffer

_Thread_local fr_log_buffer_t* fr_strerror_buffer
static

Definition at line 59 of file strerror.c.

◆ logging_stop

_Thread_local bool logging_stop
static

Due to ordering issues we may get errors being logged from within other thread local destructors which cause a crash on exit if the logging buffer has already been freed.

Definition at line 60 of file strerror.c.