Use pthread_atfork to lock/unlock yaz_log system
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 17 Feb 2014 16:59:15 +0000 (17:59 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 17 Feb 2014 16:59:15 +0000 (17:59 +0100)
include/yaz/log.h
src/log.c

index 3d7bb67..57bad18 100644 (file)
@@ -220,9 +220,6 @@ YAZ_EXPORT void log_event_end(void (*func)(int level, const char *msg,
 */
 YAZ_EXPORT void yaz_log_xml_errors(const char *prefix, int log_level);
 
-YAZ_EXPORT void yaz_log_lock(void);
-YAZ_EXPORT void yaz_log_unlock(void);
-
 YAZ_END_CDECL
 
 #endif
index b407ad9..38ecac7 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -33,6 +33,9 @@
 #include <yaz/mutex.h>
 #include <yaz/snprintf.h>
 #include <yaz/xmalloc.h>
+#if YAZ_POSIX_THREADS
+#include <pthread.h>
+#endif
 
 static int l_level = YLOG_DEFAULT_LEVEL;
 
@@ -102,12 +105,12 @@ static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* first dynamic bit */
 
 static YAZ_MUTEX log_mutex = 0;
 
-void yaz_log_lock(void)
+static void yaz_log_lock(void)
 {
     yaz_mutex_enter(log_mutex);
 }
 
-void yaz_log_unlock(void)
+static void yaz_log_unlock(void)
 {
     yaz_mutex_leave(log_mutex);
 }
@@ -123,7 +126,9 @@ static void internal_log_init(void)
 
     if (log_mutex == 0)
         yaz_mutex_create(&log_mutex);
-
+#if YAZ_POSIX_THREADS
+    pthread_atfork(yaz_log_lock, yaz_log_unlock, yaz_log_unlock);
+#endif
     env = getenv("YAZ_LOG");
     if (env)
         l_level = yaz_log_mask_str_x(env, l_level);