24
24
#include <freeradius-devel/ident.h>
25
RCSID("$Id: log.c,v 1.15 2007/12/25 08:19:38 aland Exp $")
27
27
#include <freeradius-devel/libradius.h>
29
char librad_errstr[1024];
32
* Do logging to a static buffer. Note that we MIGHT be asked
33
* to write a previous log message to librad_errstr.
35
* This also isn't multithreaded-safe, so it'll have to be changed
38
void librad_log(const char *fmt, ...)
30
#define FR_STRERROR_BUFSIZE (1024)
32
#ifdef HAVE_THREAD_TLS
34
* GCC on most Linux systems
36
#define THREAD_TLS __thread
38
#elif defined(HAVE_DECLSPEC_THREAD)
42
#define THREAD_TLS __declspec(thread)
46
* We don't have thread-local storage. Ensure we don't
52
* Use pthread keys if we have pthreads. For MAC, which should
56
#define USE_PTHREAD_FOR_TLS (1)
60
#ifndef USE_PTHREAD_FOR_TLS
62
* Try to create a thread-local-storage version of this buffer.
64
static THREAD_TLS char fr_strerror_buffer[FR_STRERROR_BUFSIZE];
69
static pthread_key_t fr_strerror_key;
70
static pthread_once_t fr_strerror_once = PTHREAD_ONCE_INIT;
73
static void fr_strerror_make_key(void)
75
pthread_key_create(&fr_strerror_key, NULL);
80
* Log to a buffer, trying to be thread-safe.
82
void fr_strerror_printf(const char *fmt, ...)
41
char my_errstr[sizeof(librad_errstr)];
44
vsnprintf(my_errstr, sizeof(my_errstr), fmt, ap);
45
strcpy(librad_errstr, my_errstr);
86
#ifdef USE_PTHREAD_FOR_TLS
89
pthread_once(&fr_strerror_once, fr_strerror_make_key);
91
buffer = pthread_getspecific(fr_strerror_key);
93
buffer = malloc(FR_STRERROR_BUFSIZE);
94
if (!buffer) return; /* panic and die! */
96
pthread_setspecific(fr_strerror_key, buffer);
100
vsnprintf(buffer, FR_STRERROR_BUFSIZE, fmt, ap);
104
vsnprintf(fr_strerror_buffer, sizeof(fr_strerror_buffer), fmt, ap);
49
void librad_perror(const char *fmt, ...)
110
const char *fr_strerror(void)
112
#ifndef USE_PTHREAD_FOR_TLS
113
return fr_strerror_buffer;
118
pthread_once(&fr_strerror_once, fr_strerror_make_key);
120
msg = pthread_getspecific(fr_strerror_key);
123
return "(unknown error)"; /* DON'T return NULL! */
127
void fr_perror(const char *fmt, ...)