]> sourceware.org Git - newlib-cygwin.git/commitdiff
cygserver: Seralize debug output to stdout to raise readability
authorCorinna Vinschen <corinna@vinschen.de>
Fri, 24 Mar 2017 15:12:00 +0000 (16:12 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Fri, 24 Mar 2017 15:12:00 +0000 (16:12 +0100)
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygserver/bsd_log.cc

index f08415432871b12da38176901cbbb92a84127aa6..2ab3526658898447427c196bfb986f2d3b6f86aa 100644 (file)
@@ -11,12 +11,16 @@ details. */
 #define __BSD_VISIBLE 1
 #include <stdio.h>
 #include <stdlib.h>
+#include <libgen.h>
 
 int32_t log_level = 8; /* Illegal value.  Don't change! */
 tun_bool_t log_debug = TUN_UNDEF;
 tun_bool_t log_syslog = TUN_UNDEF;
 tun_bool_t log_stderr = TUN_UNDEF;
 
+static CRITICAL_SECTION cs;
+static bool cs_inited;
+
 void
 loginit (tun_bool_t opt_stderr, tun_bool_t opt_syslog)
 {
@@ -43,6 +47,8 @@ loginit (tun_bool_t opt_stderr, tun_bool_t opt_syslog)
     TUNABLE_INT_FETCH ("kern.log.level", &log_level);
   if (log_level == 8)
     log_level = 6;
+  InitializeCriticalSection (&cs);
+  cs_inited = true;
 }
 
 void
@@ -63,8 +69,15 @@ _vlog (const char *file, int line, int level,
     syslog (level, buf);
   if (log_stderr == TUN_TRUE || level == LOG_DEBUG)
     {
+      if (!cs_inited)  /* Only occurs in --help scenario */
+       {
+         InitializeCriticalSection (&cs);
+         cs_inited = true;
+       }
+      EnterCriticalSection (&cs);
       fputs (buf, stderr);
       fputc ('\n', stderr);
+      LeaveCriticalSection (&cs);
     }
 }
 
This page took 0.034642 seconds and 5 git commands to generate.