24RCSID(
"$Id: bb3637fd07afbdbb9331ebcd192fc6cb2125efb5 $")
26#include <freeradius-devel/util/dlist.h>
27#include <freeradius-devel/util/strerror.h>
28#include <freeradius-devel/util/atexit.h>
32#define FR_STRERROR_BUFSIZE (2048)
99 fr_perror(
"Failed allocating memory for libradius error buffer");
103 if (!
buffer->pool_a)
goto oom;
106 if (!
buffer->pool_b)
goto oom;
137 talloc_free_children(
buffer->pool_b);
140 talloc_free_children(
buffer->pool_a);
169 fr_perror(
"Failed allocating memory for libradius error buffer");
207 if (!
fmt)
return NULL;
219 fr_perror(
"Failed allocating memory for libradius error buffer");
321 char const *subject,
size_t offset,
char const *
fmt, va_list ap)
332 entry->
subject = talloc_strdup(entry, subject);
349 char const *subject,
size_t offset,
char const *
fmt, va_list ap)
364 entry->
subject = talloc_strdup(entry, subject);
383 char const *subject,
size_t offset,
char const *
fmt, va_list ap)
398 entry->
subject = talloc_strdup(entry, subject);
418 fr_perror(
"Failed allocating memory for libradius error buffer");
479 fr_perror(
"Failed allocating memory for libradius error buffer");
563 if (!entry)
return "";
584 talloc_free_children(
buffer->pool_a);
585 talloc_free_children(
buffer->pool_b);
607 if (!entry)
return "";
636 if (!entry)
return "";
660 if (!entry)
return "";
690 if (!entry)
return NULL;
717 if (!entry)
return NULL;
744 prefix = talloc_vasprintf(NULL,
fmt, ap);
748 fprintf(stderr,
"%s: %s\n", prefix, error);
750 fprintf(stderr,
"%s\n", prefix);
757 fprintf(stderr,
"%s\n", error);
761 if (error && (error[0] !=
'\0')) {
762 fprintf(stderr,
"%s\n", error);
791 prefix = talloc_vasprintf(NULL,
fmt, ap);
805 if (error && (error[0] !=
'\0')) {
static int const char char buffer[256]
static int const char * fmt
#define fr_atexit_thread_local(_name, _free, _uctx)
static void * fr_dlist_head(fr_dlist_head_t const *list_head)
Return the HEAD item of a list or NULL if the list is empty.
static void * fr_dlist_remove(fr_dlist_head_t *list_head, void *ptr)
Remove an item from the list.
static unsigned int fr_dlist_num_elements(fr_dlist_head_t const *head)
Return the number of elements in the dlist.
static void * fr_dlist_tail(fr_dlist_head_t const *list_head)
Return the TAIL item of a list or NULL if the list is empty.
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
#define fr_dlist_talloc_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
static int fr_dlist_insert_head(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the head of a list.
static void fr_dlist_clear(fr_dlist_head_t *list_head)
Efficiently remove all elements in a dlist.
Head of a doubly linked list.
Entry in a doubly linked list.
char * fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap)
ssize_t fr_sbuff_in_sprintf(fr_sbuff_t *sbuff, char const *fmt,...)
Print using a fmt string to an sbuff.
#define fr_sbuff_start(_sbuff_or_marker)
#define FR_SBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
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.
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.
char const * msg
Log message.
size_t offset
Where to place the msg marker relative to the subject.
TALLOC_CTX * pool_b
Pool to avoid memory allocations.
static _Thread_local bool logging_stop
Due to ordering issues we may get errors being logged from within other thread local destructors whic...
char const * fr_strerror(void)
Get the last library error.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
char const * fr_strerror_peek(void)
Get the last library error.
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
TALLOC_CTX * pool
Current pool in use.
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.
char const * fr_strerror_marker_pop(char const **subject, size_t *offset)
Pop the last library error with marker information.
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.
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.
char const * subject
Subject for error markers.
TALLOC_CTX * pool_a
Pool to avoid memory allocations.
static void pool_alt_free_children(fr_log_buffer_t *buffer)
static int _fr_logging_free(void *arg)
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.
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.
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.
int line
Line where the error occurred.
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.
static _Thread_local fr_log_buffer_t * fr_strerror_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.
static fr_log_buffer_t * fr_strerror_init(void)
Initialise thread local storage.
void _fr_strerror_const(char const *file, int line, char const *msg)
Log to thread local error buffer.
#define FR_STRERROR_BUFSIZE
char const * fr_strerror_pop(void)
Pop the last library error.
static TALLOC_CTX * pool_alt(fr_log_buffer_t *buffer)
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.
char const * file
File where the error was created.
char const * fr_perror_to_str(char const *line_sep, char const *fmt,...)
Print the stack of string buffers to a thread local buffer.
char const * fr_strerror_marker_peek(char const **subject, size_t *offset)
Get the last library error marker.
char const * fr_strerror_marker(char const **subject, size_t *offset)
Get the last library error marker.
void _fr_strerror_vprintf(char const *file, int line, char const *fmt, va_list ap)
Log to thread local error buffer.
Holds data used by the logging stack.