]> mj.ucw.cz Git - libucw.git/commitdiff
log() is now signal-safe.
authorMartin Mares <mj@ucw.cz>
Wed, 14 Dec 2005 10:45:42 +0000 (10:45 +0000)
committerMartin Mares <mj@ucw.cz>
Wed, 14 Dec 2005 10:45:42 +0000 (10:45 +0000)
lib/lib.h
lib/log-file.c
lib/log.c

index a5aef116443cfa2f63d461099fed2275cde7bd4f..17944dbe2bcf9cbc12fc8886803e5a26b1e6f51b 100644 (file)
--- 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;
index 832296692f11ef78bd4e06a8b0f20109ba521b29..7fc58392572eef64865c5d65b5cc25fcac7d6124 100644 (file)
@@ -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)
index 88360004ec9ed0b91dff9215ee4ba0677a2fb791..084c72d734c0333dc359bc249409bc11e71784c3 100644 (file)
--- 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)