Go to the documentation of this file.
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)
89 #define M_FATAL (1<<4)
90 #define M_NONFATAL (1<<5)
92 #define M_DEBUG (1<<7)
94 #define M_ERRNO (1<<8)
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, ...)
151 void x_msg(
const unsigned int flags,
const char *format, ...)
153 #if __USE_MINGW_ANSI_STDIO
161 void x_msg_va(
const unsigned int flags,
const char *format, va_list arglist);
177 #define SDL_CONSTRAIN (1<<0)
191 FILE *
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)
203 void assert_failed(
const char *filename,
int line,
const char *condition)
211 #ifndef static_assert
212 #define static_assert(expr, diagnostic) \
213 extern int (*__OpenVPN_static_assert_function(void)) \
214 [!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })]
237 void open_syslog(
const char *pgmname,
bool stdio_to_null);
272 const char *description,
310 static inline const char *
344 if (!crt_error && ((err == WSAEWOULDBLOCK || err == WSAEINVAL)))
353 if (crt_error && (err == EAGAIN))
372 static inline unsigned int
384 err = GetLastError();
385 if (err == ERROR_SUCCESS)
void errors_to_stderr(void)
static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
unsigned int x_cs_info_level
unsigned int x_cs_err_delay_ms
FILE * msg_fp(const unsigned int flags)
static void set_check_status_error_delay(unsigned int milliseconds)
static void check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
void reset_check_status(void)
unsigned int x_cs_verbose_level
bool set_debug_level(const int level, const unsigned int flags)
void openvpn_exit(const int status)
void set_suppress_timestamps(bool suppressed)
static unsigned int nonfatal(const unsigned int err)
Convert fatal errors to nonfatal, don't touch other errors.
void assert_failed(const char *filename, int line, const char *condition) __attribute__((__noreturn__))
int get_debug_level(void)
void x_check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
void redirect_stdout_stderr(const char *file, bool append)
static bool ignore_sys_error(const int err, bool crt_error)
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
static const char * msg_get_prefix(void)
void set_machine_readable_output(bool parsable)
static void msg_set_prefix(const char *prefix)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
static void msg_set_virtual_output(const struct virtual_output *vo)
bool set_mute_cutoff(const int cutoff)
unsigned int x_debug_level
Garbage collection arena used to keep track of dynamically allocated memory.
void msg_thread_uninit(void)
static int openvpn_errno_maybe_crt(bool *crt_error)
const struct virtual_output * x_msg_virtual_output
void x_msg(const unsigned int flags, const char *format,...)
static bool check_debug_level(unsigned int level)
static const struct virtual_output * msg_get_virtual_output(void)
void set_check_status(unsigned int info_level, unsigned int verbose_level)
static SERVICE_STATUS status
void msg_thread_init(void)
void open_syslog(const char *pgmname, bool stdio_to_null)
int get_mute_cutoff(void)
const char * x_msg_prefix
bool dont_mute(unsigned int flags)
Check muting filter.
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
int get_orig_stderr(void)