aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wydawca.c47
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);

Return to:

Send suggestions and report system problems to the System administrator.