... by not using a heap-allocated buffer that is
shared between all threads.
This increases performance and reduces the latency
with verbose debug settings and multiple concurrent
connections.
Sponsored by: Robert Klemme
-const char errlog_rcs[] = "$Id: errlog.c,v 1.127 2016/12/24 16:00:49 fabiankeil Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.128 2017/05/29 10:06:09 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
void log_error(int loglevel, const char *fmt, ...)
{
va_list ap;
void log_error(int loglevel, const char *fmt, ...)
{
va_list ap;
- char *outbuf = NULL;
- static char *outbuf_save = NULL;
+ char outbuf[LOG_BUFFER_SIZE+1];
char tempbuf[LOG_BUFFER_SIZE];
size_t length = 0;
const char * src = fmt;
long thread_id;
char timestamp[30];
char tempbuf[LOG_BUFFER_SIZE];
size_t length = 0;
const char * src = fmt;
long thread_id;
char timestamp[30];
- /*
- * XXX: Make this a config option,
- * why else do we allocate instead of using
- * an array?
- */
const size_t log_buffer_size = LOG_BUFFER_SIZE;
#if defined(_WIN32) && !defined(_WIN_CONSOLE)
const size_t log_buffer_size = LOG_BUFFER_SIZE;
#if defined(_WIN32) && !defined(_WIN_CONSOLE)
thread_id = get_thread_id();
get_log_timestamp(timestamp, sizeof(timestamp));
thread_id = get_thread_id();
get_log_timestamp(timestamp, sizeof(timestamp));
- /* protect the whole function because of the static buffer (outbuf) */
- lock_logfile();
-
- if (NULL == outbuf_save)
- {
- outbuf_save = zalloc_or_die(log_buffer_size + 1); /* +1 for paranoia */
- }
- outbuf = outbuf_save;
-
/*
* Memsetting the whole buffer to zero (in theory)
* makes things easier later on.
*/
/*
* Memsetting the whole buffer to zero (in theory)
* makes things easier later on.
*/
- memset(outbuf, 0, log_buffer_size);
+ memset(outbuf, 0, sizeof(outbuf));
/* Add prefix for everything but Common Log Format messages */
if (loglevel != LOG_LEVEL_CLF)
/* Add prefix for everything but Common Log Format messages */
if (loglevel != LOG_LEVEL_CLF)
assert(NULL != logfp);
#endif
assert(NULL != logfp);
#endif
if (loglevel == LOG_LEVEL_FATAL)
{
if (loglevel == LOG_LEVEL_FATAL)
{
- fatal_error(outbuf_save);
/* Never get here */
}
if (logfp != NULL)
{
/* Never get here */
}
if (logfp != NULL)
{
- fputs(outbuf_save, logfp);
}
#if defined(_WIN32) && !defined(_WIN_CONSOLE)
}
#if defined(_WIN32) && !defined(_WIN_CONSOLE)