#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)
{
TUNABLE_INT_FETCH ("kern.log.level", &log_level);
if (log_level == 8)
log_level = 6;
+ InitializeCriticalSection (&cs);
+ cs_inited = true;
}
void
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);
}
}