From 65e1775cd9d57cc660064e8a7cc34f94703278ac Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 14 Dec 2005 10:45:42 +0000 Subject: [PATCH] log() is now signal-safe. --- lib/lib.h | 2 +- lib/log-file.c | 2 +- lib/log.c | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/lib.h b/lib/lib.h index a5aef116..17944dbe 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -79,7 +79,7 @@ extern char *log_title; /* NULL - print no title, default is log_progname */ extern char *log_filename; /* Expanded name of the current log file */ -extern int log_switch_nest; /* log_switch() nesting counter, increment to disable automatic switches */ +extern volatile int log_switch_nest; /* log_switch() nesting counter, increment to disable automatic switches */ extern int log_pid; /* 0 if shouldn't be logged */ extern void (*log_die_hook)(void); struct tm; diff --git a/lib/log-file.c b/lib/log-file.c index 83229669..7fc58392 100644 --- a/lib/log-file.c +++ b/lib/log-file.c @@ -19,7 +19,7 @@ static char *log_name_patt; static int log_params; static int log_filename_size; -int log_switch_nest; +volatile int log_switch_nest; static int do_log_switch(struct tm *tm) diff --git a/lib/log.c b/lib/log.c index 88360004..084c72d7 100644 --- a/lib/log.c +++ b/lib/log.c @@ -27,19 +27,22 @@ void vlog_msg(unsigned int cat, const char *msg, va_list args) { time_t tim = time(NULL); - struct tm *tm = localtime(&tim); + struct tm tm; byte *buf, *p; int buflen = 256; int l, l0, r; va_list args2; + if (!localtime_r(&tim, &tm)) + bzero(&tm, sizeof(tm)); + if (log_switch_hook) - log_switch_hook(tm); + log_switch_hook(&tm); while (1) { p = buf = alloca(buflen); *p++ = cat; - p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", tm); + p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", &tm); if (log_title) { if (log_pid) -- 2.39.2