diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/log.c | 4 | ||||
-rw-r--r-- | lib/pthread_safe.c | 23 |
2 files changed, 19 insertions, 8 deletions
@@ -709,12 +709,10 @@ _zlog_abort_err (const char *mess, int err, const char *file, { const static size_t buff_size = 1024; char buff[buff_size]; - char err_mess[buff_size]; - strerror_r(err, err_mess, buff_size); snprintf(buff, buff_size, "%s, in file %s, line %u, function %s, error %d \"%s\"", mess, file, line, (function ? function : "?"), - err, err_mess); + err, safe_strerror(err)); zlog_abort(buff); } diff --git a/lib/pthread_safe.c b/lib/pthread_safe.c index a8da3a71..f67e6b2a 100644 --- a/lib/pthread_safe.c +++ b/lib/pthread_safe.c @@ -65,6 +65,7 @@ safe_finish(void) pthread_key_delete(tsd_key); } +/* called when thread terminates, clean up */ static void destructor(void* data) { @@ -97,16 +98,28 @@ safe_strerror(int errnum) } } +/* Thread safe version of inet_ntoa. Never returns NULL. + * Contents of result remains intact until another call of + * a safe_ function. + */ const char * safe_inet_ntoa (struct in_addr in) { - if (qpthreads_enabled) - return inet_ntop(AF_INET, &in, thread_buff(), buff_size); - else - return inet_ntoa(in); + static const char * unknown = "Unknown address"; + const char * buff; + + buff = (qpthreads_enabled) + ? inet_ntop(AF_INET, &in, thread_buff(), buff_size) + : inet_ntoa(in); + + return buff != NULL + ? buff + : unknown; } -/* Return the thread's buffer */ +/* Return the thread's buffer, create it if necessary. + * (pthread Thread Specific Data) + */ static char * thread_buff(void) { |