34#if defined(ENABLE_PKCS11) || defined(ENABLE_MANAGEMENT)
35#define ERR_BUF_SIZE 10240
37#define ERR_BUF_SIZE 1280
46#define OPENVPN_MSG_FP stdout
47#define OPENVPN_ERROR_FP stderr
53#define OPENVPN_EXIT_STATUS_GOOD 0
54#define OPENVPN_EXIT_STATUS_ERROR 1
55#define OPENVPN_EXIT_STATUS_USAGE 1
56#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1
67#define OPENVPN_DEBUG_FILE PACKAGE ".log"
72#define openvpn_errno() GetLastError()
75#define openvpn_errno() errno
87#define M_DEBUG_LEVEL (0x0F)
90#define M_NONFATAL (1<<5)
96#define M_NOMUTE (1<<11)
97#define M_NOPREFIX (1<<12)
98#define M_USAGE_SMALL (1<<13)
99#define M_MSG_VIRT_OUT (1<<14)
100#define M_OPTERR (1<<15)
101#define M_NOLF (1<<16)
102#define M_NOIPREFIX (1<<17)
105#define M_ERR (M_FATAL | M_ERRNO)
106#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)
107#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)
115#define MUTE_LEVEL_SHIFT 24
116#define MUTE_LEVEL_MASK 0xFF
118#define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
119#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
131#define LOGLEV(log_level, mute_level, other) ((log_level) | ENCODE_MUTE_LEVEL(mute_level) | other)
142#define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}} while (false)
144#define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
146#define dmsg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
148#define dmsg(flags, ...)
151void x_msg(
const unsigned int flags,
const char *format, ...)
153#if __USE_MINGW_ANSI_STDIO
161void x_msg_va(
const unsigned int flags,
const char *format, va_list arglist);
177#define SDL_CONSTRAIN (1<<0)
191FILE *
msg_fp(
const unsigned int flags);
195#define ASSERT(x) do { if (!(x)) {assert_failed(__FILE__, __LINE__, #x);}} while (false)
197#define ASSERT(x) do { if (!(x)) {assert_failed(__FILE__, __LINE__, NULL);}} while (false)
203void assert_failed(
const char *filename,
int line,
const char *condition)
212#define static_assert(expr, diagnostic) \
213 extern int (*__OpenVPN_static_assert_function(void)) \
214 [!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })]
237void open_syslog(
const char *pgmname,
bool stdio_to_null);
272 const char *description,
306static inline const char *
340 if (!crt_error && ((err == WSAEWOULDBLOCK || err == WSAEINVAL)))
349 if (crt_error && (err == EAGAIN))
368static inline unsigned int
380 err = GetLastError();
381 if (err == ERROR_SUCCESS)
static SERVICE_STATUS status
static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
unsigned int x_debug_level
const struct virtual_output * x_msg_virtual_output
static void msg_set_prefix(const char *prefix)
void errors_to_stderr(void)
void open_syslog(const char *pgmname, bool stdio_to_null)
static unsigned int nonfatal(const unsigned int err)
Convert fatal errors to nonfatal, don't touch other errors.
unsigned int x_cs_info_level
void assert_failed(const char *filename, int line, const char *condition) __attribute__((__noreturn__))
static void msg_set_virtual_output(const struct virtual_output *vo)
static const char * msg_get_prefix(void)
bool dont_mute(unsigned int flags)
Check muting filter.
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
const char * x_msg_prefix
void x_check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
void x_msg(const unsigned int flags, const char *format,...)
int get_debug_level(void)
static bool check_debug_level(unsigned int level)
static void set_check_status_error_delay(unsigned int milliseconds)
int get_orig_stderr(void)
void redirect_stdout_stderr(const char *file, bool append)
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
bool set_mute_cutoff(const int cutoff)
static bool ignore_sys_error(const int err, bool crt_error)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
void set_check_status(unsigned int info_level, unsigned int verbose_level)
static int openvpn_errno_maybe_crt(bool *crt_error)
unsigned int x_cs_verbose_level
FILE * msg_fp(const unsigned int flags)
void openvpn_exit(const int status)
void reset_check_status(void)
static void check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
int get_mute_cutoff(void)
void set_suppress_timestamps(bool suppressed)
void set_machine_readable_output(bool parsable)
static const struct virtual_output * msg_get_virtual_output(void)
bool set_debug_level(const int level, const unsigned int flags)
unsigned int x_cs_err_delay_ms
Garbage collection arena used to keep track of dynamically allocated memory.