33#if defined(ENABLE_PKCS11) || defined(ENABLE_MANAGEMENT)
34#define ERR_BUF_SIZE 10240
36#define ERR_BUF_SIZE 1280
45#define OPENVPN_MSG_FP stdout
46#define OPENVPN_ERROR_FP stderr
52#define OPENVPN_EXIT_STATUS_GOOD 0
53#define OPENVPN_EXIT_STATUS_ERROR 1
54#define OPENVPN_EXIT_STATUS_USAGE 1
55#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1
66#define OPENVPN_DEBUG_FILE PACKAGE ".log"
71#define openvpn_errno() GetLastError()
74#define openvpn_errno() errno
86#define M_DEBUG_LEVEL (0x0F)
88#define M_FATAL (1 << 4)
89#define M_NONFATAL (1 << 5)
90#define M_WARN (1 << 6)
91#define M_DEBUG (1 << 7)
93#define M_ERRNO (1 << 8)
95#define M_NOMUTE (1 << 11)
96#define M_NOPREFIX (1 << 12)
97#define M_USAGE_SMALL (1 << 13)
98#define M_MSG_VIRT_OUT (1 << 14)
99#define M_OPTERR (1 << 15)
100#define M_NOLF (1 << 16)
101#define M_NOIPREFIX (1 << 17)
104#define M_ERR (M_FATAL | M_ERRNO)
105#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)
106#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)
114#define MUTE_LEVEL_SHIFT 24
115#define MUTE_LEVEL_MASK 0xFF
117#define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
118#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
130#define LOGLEV(log_level, mute_level, other) ((log_level) | ENCODE_MUTE_LEVEL(mute_level) | other)
141#define EXIT_FATAL(flags) \
144 if ((flags) & M_FATAL) \
150#define msg(flags, ...) \
153 if (msg_test(flags)) \
155 x_msg((flags), __VA_ARGS__); \
160#define dmsg(flags, ...) \
163 if (msg_test(flags)) \
165 x_msg((flags), __VA_ARGS__); \
170#define dmsg(flags, ...)
173void x_msg(
const unsigned int flags,
const char *format, ...)
175#if __USE_MINGW_ANSI_STDIO
183void x_msg_va(
const unsigned int flags,
const char *format, va_list arglist);
199#define SDL_CONSTRAIN (1 << 0)
213FILE *
msg_fp(
const unsigned int flags);
222 assert_failed(__FILE__, __LINE__, #x); \
231 assert_failed(__FILE__, __LINE__, NULL); \
240assert_failed(
const char *filename,
int line,
const char *condition)
249#define static_assert(expr, diagnostic) \
250 extern int (*__OpenVPN_static_assert_function( \
251 void))[!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })]
274void open_syslog(
const char *pgmname,
bool stdio_to_null);
341static inline const char *
375 if (!crt_error && ((err == WSAEWOULDBLOCK || err == WSAEINVAL)))
384 if (crt_error && (err == EAGAIN))
403static inline unsigned int
415 err = GetLastError();
416 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.