This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] cygserver: Seralize debug output to stdout to raise readability


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8d6a52287735c9f6d18f26569e5d04070162d83f

commit 8d6a52287735c9f6d18f26569e5d04070162d83f
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Mar 24 16:12:00 2017 +0100

    cygserver: Seralize debug output to stdout to raise readability
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygserver/bsd_log.cc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/winsup/cygserver/bsd_log.cc b/winsup/cygserver/bsd_log.cc
index f084154..2ab3526 100644
--- a/winsup/cygserver/bsd_log.cc
+++ b/winsup/cygserver/bsd_log.cc
@@ -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);
     }
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]