The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
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>
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_t * | fr_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_t * | strerror_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_t * | strerror_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_t * | strerror_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_t * | strerror_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_t * | fr_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... | |
Support functions to allow libraries to provide errors to their callers.
Definition in file strerror.c.
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.
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. |
struct fr_log_entry_s |
Definition at line 35 of file strerror.c.
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. |
#define FR_STRERROR_BUFSIZE (2048) |
Definition at line 32 of file strerror.c.
typedef struct fr_log_entry_s fr_log_entry_t |
Definition at line 1 of file strerror.c.
|
static |
Definition at line 69 of file strerror.c.
void _fr_strerror_const | ( | char const * | file, |
int | line, | ||
char const * | msg | ||
) |
Log to thread local error buffer.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | msg | To add to error stack. Must have a lifetime equal to that of the program. |
Definition at line 450 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | msg | To add to error stack. Must have a lifetime equal to that of the program. |
Definition at line 508 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | msg | To add to error stack. Must have a lifetime equal to that of the program. |
Definition at line 531 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | subject | to mark up. |
[in] | offset | Positive offset to show where the error should be positioned. |
[in] | fmt | Error string. |
[in] | ap | Arguments for the error string. |
Definition at line 320 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | subject | to mark up. |
[in] | offset | Positive offset to show where the error should be positioned. |
[in] | fmt | Error string. |
[in] | ap | Arguments for the error string. |
Definition at line 348 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | subject | to mark up. |
[in] | offset | Positive offset to show where the error should be positioned. |
[in] | fmt | Error string. |
[in] | ap | Arguments for the error string. |
Definition at line 382 of file strerror.c.
void _fr_strerror_vprintf | ( | char const * | file, |
int | line, | ||
char const * | fmt, | ||
va_list | ap | ||
) |
Log to thread local error buffer.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | fmt | printf style format string. If NULL clears any existing messages. |
[in] | ap | Arguments for the format string. |
Definition at line 245 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | fmt | printf style format string. |
[in] | ap | Arguments for the format string. |
Definition at line 263 of file strerror.c.
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.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | fmt | printf style format string. |
[in] | ap | Arguments for the format string. |
Definition at line 290 of file strerror.c.
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.
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
[in] | line_sep | to insert between the log lines. |
[in] | fmt | to prefix all log messages with. |
Definition at line 779 of file strerror.c.
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.
Definition at line 554 of file strerror.c.
void fr_strerror_clear | ( | void | ) |
Clears all pending messages from the talloc pools.
Definition at line 577 of file strerror.c.
|
static |
Initialise thread local storage.
Definition at line 88 of file strerror.c.
char const* fr_strerror_marker | ( | char const ** | subject, |
size_t * | offset | ||
) |
Get the last library error marker.
[out] | subject | The subject string the error relates to. |
[out] | offset | Where to place the marker. |
Definition at line 598 of file strerror.c.
char const* fr_strerror_marker_peek | ( | char const ** | subject, |
size_t * | offset | ||
) |
Get the last library error marker.
[out] | subject | The subject string the error relates to. |
[out] | offset | Where to place the marker. |
Definition at line 651 of file strerror.c.
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.
Definition at line 708 of file strerror.c.
char const* fr_strerror_peek | ( | void | ) |
Get the last library error.
Definition at line 627 of file strerror.c.
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.
Definition at line 681 of file strerror.c.
|
inlinestatic |
|
inlinestatic |
|
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.
|
inlinestatic |
Add a message to an existing stack of messages.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | buffer | to add the message to. |
[in] | msg | To add to error stack. Must have a lifetime equal to that of the program. |
Definition at line 465 of file strerror.c.
|
static |
Create an entry in the thread local logging stack, clearing all other entries.
Definition at line 149 of file strerror.c.
|
static |
Add a message to an existing stack of messages.
[in] | file | the error occurred in. |
[in] | line | the error occurred on. |
[in] | buffer | The log buffer to allocate memory from. |
[in] | fmt | printf style format string. |
[in] | ap | Arguments for the error string. |
Definition at line 201 of file strerror.c.
|
static |
Definition at line 59 of file strerror.c.
|
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.