Browse Source

[core] shared temp buffer for log_*error*()

use shared temp buffer for preparing error log entries
(each error log entry is flushed to error log;
 there is no persistent data buffering for error logs)
master
Glenn Strauss 3 months ago
parent
commit
58b9cca536
  1. 1
      src/configfile.c
  2. 15
      src/log.c
  3. 3
      src/log.h
  4. 2
      src/server.c

1
src/configfile.c

@ -1560,6 +1560,7 @@ int config_log_error_open(server *srv) {
* prior to set_defaults hook, and modules should not save a
* pointer to srv->errh until set_defaults hook or later)*/
p->defaults.errh = srv->errh = fdlog;
log_set_global_errh(srv->errh);
fdlog_free(errh);
}
cpv->v.v = errh = fdlog;

15
src/log.c

@ -23,6 +23,8 @@
#include "ck.h"
#include "fdlog.h"
static buffer *errh_b;
/* log_con_jqueue instance here to be defined in shared object (see base.h) */
connection *log_con_jqueue;
@ -163,7 +165,7 @@ log_buffer_vprintf (buffer * const b,
{
/* NOTE: log_buffer_prepare() ensures 0 != b->used */
/*assert(0 != b->used);*//*(only because code calcs below assume this)*/
/*assert(0 != b->size);*//*(errh->b should not have 0 size here)*/
/*assert(0 != b->size);*//*(b has non-size after log_buffer_prepare())*/
size_t blen = buffer_clen(b);
size_t bsp = buffer_string_space(b)+1;
char *s = b->ptr + blen;
@ -214,7 +216,7 @@ log_error_va_list_impl (log_error_st * const errh,
const int perr)
{
const int errnum = errno;
buffer * const b = &errh->b;
buffer * const b = errh_b ? errh_b : &errh->b;
if (-1 == log_buffer_prepare(errh, filename, line, b)) return;
log_buffer_vprintf(b, fmt, ap);
if (perr)
@ -259,7 +261,7 @@ log_error_multiline (log_error_st * const restrict errh,
if (0 == len) return;
const int errnum = errno;
buffer * const b = &errh->b;
buffer * const b = errh_b ? errh_b : &errh->b;
if (-1 == log_buffer_prepare(errh, filename, line, b)) return;
va_list ap;
@ -283,3 +285,10 @@ log_error_multiline (log_error_st * const restrict errh,
errno = errnum;
}
void
log_set_global_errh (log_error_st * const errh)
{
errh_b = errh ? &errh->b : NULL;
}

3
src/log.h

@ -30,4 +30,7 @@ __attribute_cold__
__attribute_format__((__printf__, 6, 7))
void log_error_multiline(log_error_st *errh, const char *filename, unsigned int line, const char * restrict multiline, const size_t len, const char *fmt, ...);
__attribute_cold__
void log_set_global_errh (log_error_st *errh);
#endif

2
src/server.c

@ -308,6 +308,7 @@ static server *server_init(void) {
log_monotonic_secs = server_monotonic_secs();
srv->errh = fdlog_init(NULL, STDERR_FILENO, FDLOG_FD);
log_set_global_errh(srv->errh);
config_init(srv);
@ -352,6 +353,7 @@ static void server_free(server *srv) {
li_rand_cleanup();
chunkqueue_chunk_pool_free();
log_set_global_errh(NULL);
fdlog_free(srv->errh);
free(srv);
}

Loading…
Cancel
Save