24RCSID(
"$Id: 253b4d36a0657a0ba72bb31dea7fd462a637d718 $")
26#include <freeradius-devel/util/log.h>
27#include <freeradius-devel/util/strerror.h>
28#include <freeradius-devel/util/syserror.h>
29#include <freeradius-devel/util/atexit.h>
32#define FR_SYSERROR_BUFSIZE (2048)
40#define HAVE_DEFINITION(_errno) ((_errno) < (int)(NUM_ELEMENTS(fr_syserror_macro_names)))
61 [EADDRINUSE] =
"EADDRINUSE",
62 [EADDRNOTAVAIL] =
"EADDRNOTAVAIL",
63 [EAFNOSUPPORT] =
"EAFNOSUPPORT",
64#if EWOULDBLOCK == EAGAIN
65 [EWOULDBLOCK] =
"EWOULDBLOCK or EAGAIN",
68 [EWOULDBLOCK] =
"EWOULDBLOCK",
70 [EALREADY] =
"EALREADY",
72 [EBADMSG] =
"EBADMSG",
74 [ECANCELED] =
"ECANCELED",
76 [ECONNABORTED] =
"ECONNABORTED",
77 [ECONNREFUSED] =
"ECONNREFUSED",
78 [ECONNRESET] =
"ECONNRESET",
79 [EDEADLK] =
"EDEADLK",
80 [EDESTADDRREQ] =
"EDESTADDRREQ",
86 [EHOSTUNREACH] =
"EHOSTUNREACH",
89 [EINPROGRESS] =
"EINPROGRESS",
93 [EISCONN] =
"EISCONN",
98 [EMSGSIZE] =
"EMSGSIZE",
99 [EMULTIHOP] =
"EMULTIHOP",
100 [ENAMETOOLONG] =
"ENAMETOOLONG",
101 [ENETDOWN] =
"ENETDOWN",
102 [ENETRESET] =
"ENETRESET",
103 [ENETUNREACH] =
"ENETUNREACH",
105 [ENOBUFS] =
"ENOBUFS",
107 [ENODATA] =
"ENODATA",
111 [ENOEXEC] =
"ENOEXEC",
113 [ENOLINK] =
"ENOLINK",
116 [ENOPROTOOPT] =
"ENOPROTOOPT",
125 [ENOTCONN] =
"ENOTCONN",
126 [ENOTDIR] =
"ENOTDIR",
127 [ENOTEMPTY] =
"ENOTEMPTY",
128#ifdef ENOTRECOVERABLE
129 [ENOTRECOVERABLE] =
"ENOTRECOVERABLE",
131 [ENOTSOCK] =
"ENOTSOCK",
132#if ENOTSUP == EOPNOTSUPP
133 [ENOTSUP] =
"ENOTSUP or EOPNOTSUPP",
135 [ENOTSUP] =
"ENOTSUP",
136 [EOPNOTSUPP] =
"EOPNOTSUPP",
140 [EOVERFLOW] =
"EOVERFLOW",
142 [EOWNERDEAD] =
"EOWNERDEAD",
147 [EPROTONOSUPPORT] =
"EPROTONOSUPPORT",
148 [EPROTOTYPE] =
"EPROTOTYPE",
157 [ETIMEDOUT] =
"ETIMEDOUT",
158 [ETXTBSY] =
"ETXTBSY",
162static inline CC_HINT(always_inline)
168#if !defined(HAVE_FEATURES_H) || !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 500) && ! _GNU_SOURCE)
172 ret = strerror_r(num,
buffer, buff_len);
175 fprintf(stderr,
"strerror_r() failed to write error for errno %i to buffer %p (%zu bytes), "
193 q = strerror_r(num,
buffer, buff_len);
196 fprintf(stderr,
"strerror_r() failed to write error for errno %i to buffer %p "
210 if (len >= buff_len) len = buff_len;
219static inline CC_HINT(always_inline)
228 fr_perror(
"Failed allocating memory for system error buffer");
257 if (num == 0)
return "No additional error information";
275 p +=
snprintf(p, end - p,
"errno %i: ", num);
277 if (p >= end)
return p;
static int const char char buffer[256]
#define fr_atexit_thread_local(_name, _free, _uctx)
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
size_t strlcpy(char *dst, char const *src, size_t siz)
static int _fr_logging_free(UNUSED void *arg)
#define FR_SYSERROR_BUFSIZE
static _Thread_local bool logging_stop
Due to ordering issues we may get errors being logged from within other thread local destructors whic...
#define HAVE_DEFINITION(_errno)
char const * fr_syserror_simple(int num)
Guaranteed to be thread-safe version of strerror.
static ssize_t _fr_syserror(int num, char *buffer, size_t buff_len)
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
static _Thread_local char * fr_syserror_buffer
static char const * fr_syserror_macro_names[]
POSIX-2008 errno macros.
static char * _fr_syserror_buffer(void)
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.