From a7fc20538dc1a483eb77aa94d182f3e1f27f1ce8 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 9 Dec 2006 22:39:36 +0100 Subject: [PATCH] Logging functions are thread-safe. --- lib/THREADS | 1 - lib/log-file.c | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/THREADS b/lib/THREADS index 9593c217..69452b57 100644 --- a/lib/THREADS +++ b/lib/THREADS @@ -4,6 +4,5 @@ which also includes functions acting on any kind of global state. There are some exceptions: -- logging functions are safe as long as you don't switch log files - setproctitle() is not safe, it modifies global state - handle_signal() is not safe, it modifies global state diff --git a/lib/log-file.c b/lib/log-file.c index 20dea918..1ef69a14 100644 --- a/lib/log-file.c +++ b/lib/log-file.c @@ -1,7 +1,7 @@ /* * UCW Library -- Keeping of Log Files * - * (c) 1997--2005 Martin Mares + * (c) 1997--2006 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -9,6 +9,7 @@ #include "lib/lib.h" #include "lib/lfs.h" +#include "lib/threads.h" #include #include @@ -31,6 +32,7 @@ do_log_switch(struct tm *tm) if (!log_name_patt || log_filename[0] && !log_params) return 0; + ucwlib_lock(); log_switch_nest++; l = strftime(name, log_filename_size, log_name_patt, tm); if (l < 0 || l >= log_filename_size) @@ -49,6 +51,7 @@ do_log_switch(struct tm *tm) switched = 1; } log_switch_nest--; + ucwlib_unlock(); return switched; } -- 2.39.2