cygserver: Seralize debug output to stdout to raise readability
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
		| @@ -11,12 +11,16 @@ details. */ | |||||||
| #define __BSD_VISIBLE 1 | #define __BSD_VISIBLE 1 | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <libgen.h> | ||||||
|  |  | ||||||
| int32_t log_level = 8; /* Illegal value.  Don't change! */ | int32_t log_level = 8; /* Illegal value.  Don't change! */ | ||||||
| tun_bool_t log_debug = TUN_UNDEF; | tun_bool_t log_debug = TUN_UNDEF; | ||||||
| tun_bool_t log_syslog = TUN_UNDEF; | tun_bool_t log_syslog = TUN_UNDEF; | ||||||
| tun_bool_t log_stderr = TUN_UNDEF; | tun_bool_t log_stderr = TUN_UNDEF; | ||||||
|  |  | ||||||
|  | static CRITICAL_SECTION cs; | ||||||
|  | static bool cs_inited; | ||||||
|  |  | ||||||
| void | void | ||||||
| loginit (tun_bool_t opt_stderr, tun_bool_t opt_syslog) | 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); |     TUNABLE_INT_FETCH ("kern.log.level", &log_level); | ||||||
|   if (log_level == 8) |   if (log_level == 8) | ||||||
|     log_level = 6; |     log_level = 6; | ||||||
|  |   InitializeCriticalSection (&cs); | ||||||
|  |   cs_inited = true; | ||||||
| } | } | ||||||
|  |  | ||||||
| void | void | ||||||
| @@ -63,8 +69,15 @@ _vlog (const char *file, int line, int level, | |||||||
|     syslog (level, buf); |     syslog (level, buf); | ||||||
|   if (log_stderr == TUN_TRUE || level == LOG_DEBUG) |   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); |       fputs (buf, stderr); | ||||||
|       fputc ('\n', stderr); |       fputc ('\n', stderr); | ||||||
|  |       LeaveCriticalSection (&cs); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user