]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Workaround thread-unsafeness of cli_echo().
authorOndrej Zajicek <santiago@crfreenet.org>
Fri, 7 Feb 2014 12:09:55 +0000 (13:09 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 7 Feb 2014 12:09:55 +0000 (13:09 +0100)
sysdep/unix/log.c
sysdep/unix/main.c
sysdep/unix/unix.h

index 0f4c06e9ce810a1f2cfdb92f4eb824de1341b8be..66a5581ce589da7072f4561f39c33e5292cc361a 100644 (file)
@@ -39,14 +39,21 @@ static const int rate_limit_count = 5;
 #ifdef USE_PTHREADS
 
 #include <pthread.h>
+
 static pthread_mutex_t log_mutex;
 static inline void log_lock(void) { pthread_mutex_lock(&log_mutex); }
 static inline void log_unlock(void) { pthread_mutex_unlock(&log_mutex); }
 
+static pthread_t main_thread;
+void main_thread_init(void) { main_thread = pthread_self(); }
+static int main_thread_self(void) { return pthread_equal(pthread_self(), main_thread); }
+
 #else
 
 static inline void log_lock(void) {  }
 static inline void log_unlock(void) {  }
+void main_thread_init(void) { }
+static int main_thread_self(void) { return 1; }
 
 #endif
 
@@ -128,8 +135,9 @@ log_commit(int class, buffer *buf)
     }
   log_unlock();
 
-  /* FIXME: cli_echo is not thread-safe */
-  cli_echo(class, buf->start);
+  /* cli_echo is not thread-safe, so call it just from the main thread */
+  if (main_thread_self())
+    cli_echo(class, buf->start);
 
   buf->pos = buf->start;
 }
index 7a945826298997d3c1050511326c6264c1e9e18a..e9217bc94d777be1e346475a5caecffdfd184241 100644 (file)
@@ -797,6 +797,8 @@ main(int argc, char **argv)
       dup2(0, 2);
     }
 
+  main_thread_init();
+
   write_pid_file();
 
   signal_init();
index 1fc26db2a774bd11a47b821e1d5acc941b5ac9a3..346adcf2b2f8e03195fa336690ed34e0e9bfc46a 100644 (file)
@@ -67,6 +67,7 @@ void krt_io_init(void);
 
 /* log.c */
 
+void main_thread_init(void);
 void log_init_debug(char *);           /* Initialize debug dump to given file (NULL=stderr, ""=off) */
 void log_switch(int debug, list *l, char *); /* Use l=NULL for initial switch */