diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-05-02 22:50:28 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-05-02 22:50:28 +0300 |
commit | 2965b67eeb48d4c6ddbb9829a5fa1250fe635685 (patch) | |
tree | 5e023f1c8e26f503c9c95a6fd5007e0dfea383d1 /src/wydawca.c | |
parent | 261f21f568ba5d61d9130079ab5d4aa698ff64e9 (diff) | |
download | wydawca-2965b67eeb48d4c6ddbb9829a5fa1250fe635685.tar.gz wydawca-2965b67eeb48d4c6ddbb9829a5fa1250fe635685.tar.bz2 |
Fix syslog logging if print-priority is set to truerelease-4.0.1
Diffstat (limited to 'src/wydawca.c')
-rw-r--r-- | src/wydawca.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/src/wydawca.c b/src/wydawca.c index dbbda11..635a158 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -57,21 +57,54 @@ unsigned max_directive_version = MAX_DIRECTIVE_VERSION; int inotify_enable = 1; /* Logging */ +static pthread_key_t strbuf_key; +static pthread_once_t strbuf_key_once = PTHREAD_ONCE_INIT; + +struct strbuf { + char *buf; + size_t size; +}; + +static void +strbuf_free(void *f) +{ + struct strbuf *sb = f; + free(sb->buf); + free(sb); +} + +static void +make_strbuf_key(void) +{ + pthread_key_create(&strbuf_key, strbuf_free); +} + +static struct strbuf * +syslog_get_strbuf(void) +{ + struct strbuf *sb; + pthread_once(&strbuf_key_once, make_strbuf_key); + if ((sb = pthread_getspecific(strbuf_key)) == NULL) { + sb = grecs_zalloc(sizeof(*sb)); + pthread_setspecific(strbuf_key, sb); + } + return sb; +} + void syslog_printer(int prio, const char *fmt, va_list ap) { if (syslog_include_prio) { - static char *fmtbuf; - static size_t fmtsize; + struct strbuf *sb = syslog_get_strbuf(); const char *p = wy_pritostr(prio); size_t size = strlen(p) + 3 + strlen(fmt) + 1; - if (size > fmtsize) { - fmtsize = size; - fmtbuf = grecs_realloc(fmtbuf, fmtsize); + if (size > sb->size) { + sb->size = size; + sb->buf = grecs_realloc(sb->buf, sb->size); } - sprintf(fmtbuf, "[%s] %s", p, fmt); - fmt = fmtbuf; + sprintf(sb->buf, "[%s] %s", p, fmt); + fmt = sb->buf; } #if HAVE_VSYSLOG vsyslog(prio, fmt, ap); |