37 #define ERR_BUF_SIZE 8192 39 #define ERR_BUF_SIZE 1280 48 #define OPENVPN_MSG_FP stdout 49 #define OPENVPN_ERROR_FP stderr 55 #define OPENVPN_EXIT_STATUS_GOOD 0 56 #define OPENVPN_EXIT_STATUS_ERROR 1 57 #define OPENVPN_EXIT_STATUS_USAGE 1 58 #define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1 69 #define OPENVPN_DEBUG_FILE PACKAGE ".log" 74 #define openvpn_errno() GetLastError() 75 #define openvpn_strerror(e, gc) strerror_win32(e, gc) 79 #define openvpn_errno() errno 80 #define openvpn_strerror(x, gc) strerror(x) 92 #define M_DEBUG_LEVEL (0x0F) 94 #define M_FATAL (1<<4) 95 #define M_NONFATAL (1<<5) 97 #define M_DEBUG (1<<7) 99 #define M_ERRNO (1<<8) 101 #define M_NOMUTE (1<<11) 102 #define M_NOPREFIX (1<<12) 103 #define M_USAGE_SMALL (1<<13) 104 #define M_MSG_VIRT_OUT (1<<14) 105 #define M_OPTERR (1<<15) 106 #define M_NOLF (1<<16) 107 #define M_NOIPREFIX (1<<17) 110 #define M_ERR (M_FATAL | M_ERRNO) 111 #define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR) 112 #define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX) 120 #define MUTE_LEVEL_SHIFT 24 121 #define MUTE_LEVEL_MASK 0xFF 123 #define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT) 124 #define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK) 136 #define LOGLEV(log_level, mute_level, other) ((log_level) | ENCODE_MUTE_LEVEL(mute_level) | other) 147 #define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}} while (false) 149 #if defined(HAVE_CPP_VARARG_MACRO_ISO) && !defined(__LCLINT__) 150 #define HAVE_VARARG_MACROS 151 #define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false) 153 #define dmsg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false) 155 #define dmsg(flags, ...) 157 #elif defined(HAVE_CPP_VARARG_MACRO_GCC) && !defined(__LCLINT__) 158 #define HAVE_VARARG_MACROS 159 #define msg(flags, args ...) do { if (msg_test(flags)) {x_msg((flags), args);} EXIT_FATAL(flags); } while (false) 161 #define dmsg(flags, args ...) do { if (msg_test(flags)) {x_msg((flags), args);} EXIT_FATAL(flags); } while (false) 163 #define dmsg(flags, args ...) 168 #pragma message("this compiler appears to lack vararg macros which will cause a significant degradation in efficiency") 170 #warning this compiler appears to lack vararg macros which will cause a significant degradation in efficiency (you can ignore this warning if you are using LCLINT) 177 void x_msg(
const unsigned int flags,
const char *format, ...)
179 #if __USE_MINGW_ANSI_STDIO 180 __attribute__ ((format(gnu_printf, 2, 3)))
182 __attribute__ ((format(__printf__, 2, 3)))
187 void x_msg_va(
const unsigned int flags,
const char *format, va_list arglist);
203 #define SDL_CONSTRAIN (1<<0) 217 FILE *
msg_fp(
const unsigned int flags);
221 #define ASSERT(x) do { if (!(x)) {assert_failed(__FILE__, __LINE__, #x);}} while (false) 223 #define ASSERT(x) do { if (!(x)) {assert_failed(__FILE__, __LINE__, NULL);}} while (false) 226 void assert_failed(
const char *filename,
int line,
const char *condition)
227 __attribute__((__noreturn__));
231 #ifndef static_assert 232 #define static_assert(expr, diagnostic) \ 233 extern int (*__OpenVPN_static_assert_function(void)) \ 234 [!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })] 262 void open_syslog(
const char *pgmname,
bool stdio_to_null);
297 const char *description,
313 x_cs_err_delay_ms = milliseconds;
332 x_msg_prefix = prefix;
335 static inline const char *
352 x_msg_virtual_output = vo;
370 if (err == WSAEWOULDBLOCK || err == WSAEINVAL)
395 static inline unsigned int static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
void x_check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
static unsigned int nonfatal(const unsigned int err)
Convert fatal errors to nonfatal, don't touch other errors.
void msg_thread_init(void)
static bool check_debug_level(unsigned int level)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
HANDLE get_orig_stderr(void)
static const char * msg_get_prefix(void)
void set_machine_readable_output(bool parsable)
void openvpn_exit(const int status)
void set_check_status(unsigned int info_level, unsigned int verbose_level)
bool dont_mute(unsigned int flags)
Check muting filter.
static void msg_set_prefix(const char *prefix)
void set_suppress_timestamps(bool suppressed)
static bool ignore_sys_error(const int err)
static void msg_set_virtual_output(const struct virtual_output *vo)
unsigned int x_cs_info_level
static const struct virtual_output * msg_get_virtual_output(void)
FILE * msg_fp(const unsigned int flags)
int get_mute_cutoff(void)
static SERVICE_STATUS status
bool set_mute_cutoff(const int cutoff)
void open_syslog(const char *pgmname, bool stdio_to_null)
void msg_thread_uninit(void)
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
void reset_check_status(void)
const char * x_msg_prefix
static void set_check_status_error_delay(unsigned int milliseconds)
void errors_to_stderr(void)
unsigned int x_debug_level
int get_debug_level(void)
void redirect_stdout_stderr(const char *file, bool append)
Garbage collection arena used to keep track of dynamically allocated memory.
void x_msg(const unsigned int flags, const char *format,...)
const struct virtual_output * x_msg_virtual_output
void assert_failed(const char *filename, int line, const char *condition) __attribute__((__noreturn__))
unsigned int x_cs_err_delay_ms
unsigned int x_cs_verbose_level
static void check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
bool set_debug_level(const int level, const unsigned int flags)