OpenVPN
Macros | Functions | Variables
error.h File Reference
#include "basic.h"
#include "syshead.h"
#include <assert.h>
#include "errlevel.h"
Include dependency graph for error.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ERR_BUF_SIZE   10240
 
#define OPENVPN_MSG_FP   stdout
 
#define OPENVPN_ERROR_FP   stderr
 
#define OPENVPN_EXIT_STATUS_GOOD   0
 
#define OPENVPN_EXIT_STATUS_ERROR   1
 
#define OPENVPN_EXIT_STATUS_USAGE   1
 
#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE   1
 
#define OPENVPN_DEBUG_FILE   PACKAGE ".log"
 
#define openvpn_errno()   GetLastError()
 
#define M_DEBUG_LEVEL   (0x0F) /* debug level mask */
 
#define M_FATAL   (1<<4) /* exit program */
 
#define M_NONFATAL   (1<<5) /* non-fatal error */
 
#define M_WARN   (1<<6) /* call syslog with LOG_WARNING */
 
#define M_DEBUG   (1<<7)
 
#define M_ERRNO   (1<<8) /* show errno description */
 
#define M_NOMUTE   (1<<11) /* don't do mute processing */
 
#define M_NOPREFIX   (1<<12) /* don't show date/time prefix */
 
#define M_USAGE_SMALL   (1<<13) /* fatal options error, call usage_small */
 
#define M_MSG_VIRT_OUT   (1<<14) /* output message through msg_status_output callback */
 
#define M_OPTERR   (1<<15) /* print "Options error:" prefix */
 
#define M_NOLF   (1<<16) /* don't print new line */
 
#define M_NOIPREFIX   (1<<17) /* don't print instance prefix */
 
#define M_ERR   (M_FATAL | M_ERRNO)
 
#define M_USAGE   (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)
 
#define M_CLIENT   (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)
 
#define MUTE_LEVEL_SHIFT   24
 
#define MUTE_LEVEL_MASK   0xFF
 
#define ENCODE_MUTE_LEVEL(mute_level)   (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
 
#define DECODE_MUTE_LEVEL(flags)   (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
 
#define LOGLEV(log_level, mute_level, other)   ((log_level) | ENCODE_MUTE_LEVEL(mute_level) | other)
 
#define EXIT_FATAL(flags)   do { if ((flags) & M_FATAL) {_exit(1);}} while (false)
 
#define msg(flags, ...)   do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
 
#define dmsg(flags, ...)
 
#define SDL_CONSTRAIN   (1<<0)
 
#define ASSERT(x)   do { if (!(x)) {assert_failed(__FILE__, __LINE__, #x);}} while (false)
 
#define static_assert(expr, diagnostic)
 

Functions

const char * strerror_win32 (DWORD errnum, struct gc_arena *gc)
 
bool dont_mute (unsigned int flags)
 Check muting filter. More...
 
void x_msg (const unsigned int flags, const char *format,...)
 
void x_msg_va (const unsigned int flags, const char *format, va_list arglist)
 
void error_reset (void)
 
void errors_to_stderr (void)
 
void set_suppress_timestamps (bool suppressed)
 
void set_machine_readable_output (bool parsable)
 
bool set_debug_level (const int level, const unsigned int flags)
 
bool set_mute_cutoff (const int cutoff)
 
int get_debug_level (void)
 
int get_mute_cutoff (void)
 
const char * msg_flags_string (const unsigned int flags, struct gc_arena *gc)
 
FILE * msg_fp (const unsigned int flags)
 
void assert_failed (const char *filename, int line, const char *condition) __attribute__((__noreturn__))
 
static bool check_debug_level (unsigned int level)
 
static bool msg_test (unsigned int flags)
 Return true if flags represent an enabled, not muted log level. More...
 
void msg_forked (void)
 
void open_syslog (const char *pgmname, bool stdio_to_null)
 
void close_syslog (void)
 
void redirect_stdout_stderr (const char *file, bool append)
 
int get_orig_stderr (void)
 
void openvpn_exit (const int status)
 
void out_of_memory (void)
 
void reset_check_status (void)
 
void set_check_status (unsigned int info_level, unsigned int verbose_level)
 
void x_check_status (int status, const char *description, struct link_socket *sock, struct tuntap *tt)
 
static void check_status (int status, const char *description, struct link_socket *sock, struct tuntap *tt)
 
static void set_check_status_error_delay (unsigned int milliseconds)
 
void msg_thread_init (void)
 
void msg_thread_uninit (void)
 
static void msg_set_prefix (const char *prefix)
 
static const char * msg_get_prefix (void)
 
static void msg_set_virtual_output (const struct virtual_output *vo)
 
static const struct virtual_outputmsg_get_virtual_output (void)
 
static bool ignore_sys_error (const int err, bool crt_error)
 
static unsigned int nonfatal (const unsigned int err)
 Convert fatal errors to nonfatal, don't touch other errors. More...
 
static int openvpn_errno_maybe_crt (bool *crt_error)
 

Variables

unsigned int x_debug_level
 
int x_msg_line_num
 
unsigned int x_cs_info_level
 
unsigned int x_cs_verbose_level
 
unsigned int x_cs_err_delay_ms
 
const char * x_msg_prefix
 
const struct virtual_outputx_msg_virtual_output
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   x)    do { if (!(x)) {assert_failed(__FILE__, __LINE__, #x);}} while (false)

Definition at line 195 of file error.h.

◆ DECODE_MUTE_LEVEL

#define DECODE_MUTE_LEVEL (   flags)    (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)

Definition at line 119 of file error.h.

◆ dmsg

#define dmsg (   flags,
  ... 
)

Definition at line 148 of file error.h.

◆ ENCODE_MUTE_LEVEL

#define ENCODE_MUTE_LEVEL (   mute_level)    (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)

Definition at line 118 of file error.h.

◆ ERR_BUF_SIZE

#define ERR_BUF_SIZE   10240

Definition at line 35 of file error.h.

◆ EXIT_FATAL

#define EXIT_FATAL (   flags)    do { if ((flags) & M_FATAL) {_exit(1);}} while (false)

Definition at line 142 of file error.h.

◆ LOGLEV

#define LOGLEV (   log_level,
  mute_level,
  other 
)    ((log_level) | ENCODE_MUTE_LEVEL(mute_level) | other)

Definition at line 131 of file error.h.

◆ M_CLIENT

#define M_CLIENT   (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)

Definition at line 107 of file error.h.

◆ M_DEBUG

#define M_DEBUG   (1<<7)

Definition at line 92 of file error.h.

◆ M_DEBUG_LEVEL

#define M_DEBUG_LEVEL   (0x0F) /* debug level mask */

Definition at line 87 of file error.h.

◆ M_ERR

#define M_ERR   (M_FATAL | M_ERRNO)

Definition at line 105 of file error.h.

◆ M_ERRNO

#define M_ERRNO   (1<<8) /* show errno description */

Definition at line 94 of file error.h.

◆ M_FATAL

#define M_FATAL   (1<<4) /* exit program */

Definition at line 89 of file error.h.

◆ M_MSG_VIRT_OUT

#define M_MSG_VIRT_OUT   (1<<14) /* output message through msg_status_output callback */

Definition at line 99 of file error.h.

◆ M_NOIPREFIX

#define M_NOIPREFIX   (1<<17) /* don't print instance prefix */

Definition at line 102 of file error.h.

◆ M_NOLF

#define M_NOLF   (1<<16) /* don't print new line */

Definition at line 101 of file error.h.

◆ M_NOMUTE

#define M_NOMUTE   (1<<11) /* don't do mute processing */

Definition at line 96 of file error.h.

◆ M_NONFATAL

#define M_NONFATAL   (1<<5) /* non-fatal error */

Definition at line 90 of file error.h.

◆ M_NOPREFIX

#define M_NOPREFIX   (1<<12) /* don't show date/time prefix */

Definition at line 97 of file error.h.

◆ M_OPTERR

#define M_OPTERR   (1<<15) /* print "Options error:" prefix */

Definition at line 100 of file error.h.

◆ M_USAGE

#define M_USAGE   (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)

Definition at line 106 of file error.h.

◆ M_USAGE_SMALL

#define M_USAGE_SMALL   (1<<13) /* fatal options error, call usage_small */

Definition at line 98 of file error.h.

◆ M_WARN

#define M_WARN   (1<<6) /* call syslog with LOG_WARNING */

Definition at line 91 of file error.h.

◆ msg

#define msg (   flags,
  ... 
)    do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)

Definition at line 144 of file error.h.

◆ MUTE_LEVEL_MASK

#define MUTE_LEVEL_MASK   0xFF

Definition at line 116 of file error.h.

◆ MUTE_LEVEL_SHIFT

#define MUTE_LEVEL_SHIFT   24

Definition at line 115 of file error.h.

◆ OPENVPN_DEBUG_FILE

#define OPENVPN_DEBUG_FILE   PACKAGE ".log"

Definition at line 67 of file error.h.

◆ openvpn_errno

#define openvpn_errno ( )    GetLastError()

Definition at line 72 of file error.h.

◆ OPENVPN_ERROR_FP

#define OPENVPN_ERROR_FP   stderr

Definition at line 47 of file error.h.

◆ OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE

#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE   1

Definition at line 56 of file error.h.

◆ OPENVPN_EXIT_STATUS_ERROR

#define OPENVPN_EXIT_STATUS_ERROR   1

Definition at line 54 of file error.h.

◆ OPENVPN_EXIT_STATUS_GOOD

#define OPENVPN_EXIT_STATUS_GOOD   0

Definition at line 53 of file error.h.

◆ OPENVPN_EXIT_STATUS_USAGE

#define OPENVPN_EXIT_STATUS_USAGE   1

Definition at line 55 of file error.h.

◆ OPENVPN_MSG_FP

#define OPENVPN_MSG_FP   stdout

Definition at line 46 of file error.h.

◆ SDL_CONSTRAIN

#define SDL_CONSTRAIN   (1<<0)

Definition at line 177 of file error.h.

◆ static_assert

#define static_assert (   expr,
  diagnostic 
)
Value:
extern int (*__OpenVPN_static_assert_function(void)) \
[!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })]

Definition at line 212 of file error.h.

Function Documentation

◆ assert_failed()

void assert_failed ( const char *  filename,
int  line,
const char *  condition 
)

Definition at line 442 of file error.c.

References M_FATAL, and msg.

◆ check_debug_level()

static bool check_debug_level ( unsigned int  level)
inlinestatic

◆ check_status()

static void check_status ( int  status,
const char *  description,
struct link_socket sock,
struct tuntap tt 
)
inlinestatic

◆ close_syslog()

void close_syslog ( void  )

Definition at line 491 of file error.c.

References use_syslog.

Referenced by openvpn_exit().

◆ dont_mute()

bool dont_mute ( unsigned int  flags)

Check muting filter.

Definition at line 407 of file error.c.

Referenced by msg_test().

◆ error_reset()

void error_reset ( void  )

◆ errors_to_stderr()

void errors_to_stderr ( void  )

Definition at line 185 of file error.c.

References default_err, and OPENVPN_ERROR_FP.

Referenced by add_option().

◆ get_debug_level()

int get_debug_level ( void  )

Definition at line 137 of file error.c.

References x_debug_level.

Referenced by man_dispatch_command().

◆ get_mute_cutoff()

int get_mute_cutoff ( void  )

Definition at line 143 of file error.c.

References mute_cutoff.

Referenced by man_dispatch_command().

◆ get_orig_stderr()

int get_orig_stderr ( void  )

Definition at line 508 of file error.c.

References orig_stderr.

Referenced by get_console_input_win32().

◆ ignore_sys_error()

static bool ignore_sys_error ( const int  err,
bool  crt_error 
)
inlinestatic

Definition at line 341 of file error.h.

Referenced by man_io_error(), and x_check_status().

◆ msg_flags_string()

const char* msg_flags_string ( const unsigned int  flags,
struct gc_arena gc 
)

Definition at line 783 of file error.c.

References alloc_buf_gc(), BSTR, buf_printf(), M_DEBUG, M_FATAL, M_INFO, M_NONFATAL, and M_WARN.

Referenced by log_entry_print().

◆ msg_forked()

void msg_forked ( void  )

Definition at line 99 of file error.c.

References forked.

◆ msg_fp()

FILE* msg_fp ( const unsigned int  flags)

◆ msg_get_prefix()

static const char* msg_get_prefix ( void  )
inlinestatic

Definition at line 311 of file error.h.

References x_msg_prefix.

Referenced by x_msg_va().

◆ msg_get_virtual_output()

static const struct virtual_output* msg_get_virtual_output ( void  )
inlinestatic

Definition at line 331 of file error.h.

References x_msg_virtual_output.

Referenced by x_msg_va().

◆ msg_set_prefix()

static void msg_set_prefix ( const char *  prefix)
inlinestatic

Definition at line 305 of file error.h.

References x_msg_prefix.

Referenced by clear_prefix(), multi_process_outgoing_link(), and set_prefix().

◆ msg_set_virtual_output()

static void msg_set_virtual_output ( const struct virtual_output vo)
inlinestatic

Definition at line 325 of file error.h.

References x_msg_virtual_output.

Referenced by man_persist_close(), and man_persist_init().

◆ msg_test()

static bool msg_test ( unsigned int  flags)
inlinestatic

Return true if flags represent an enabled, not muted log level.

Definition at line 227 of file error.h.

References check_debug_level(), and dont_mute().

Referenced by plugin_vlog(), and x_msg_va().

◆ msg_thread_init()

void msg_thread_init ( void  )

◆ msg_thread_uninit()

void msg_thread_uninit ( void  )

◆ nonfatal()

static unsigned int nonfatal ( const unsigned int  err)
inlinestatic

Convert fatal errors to nonfatal, don't touch other errors.

Definition at line 373 of file error.h.

References M_FATAL, and M_NONFATAL.

◆ open_syslog()

void open_syslog ( const char *  pgmname,
bool  stdio_to_null 
)

Definition at line 467 of file error.c.

References M_WARN, msg, msgfp, PACKAGE, set_std_files_to_null(), std_redir, string_alloc(), and use_syslog.

Referenced by add_option().

◆ openvpn_errno_maybe_crt()

static int openvpn_errno_maybe_crt ( bool *  crt_error)
inlinestatic

Definition at line 379 of file error.h.

Referenced by man_io_error(), x_check_status(), and x_msg_va().

◆ openvpn_exit()

void openvpn_exit ( const int  status)

◆ out_of_memory()

void out_of_memory ( void  )

Definition at line 460 of file error.c.

References PACKAGE_NAME.

Referenced by check_malloc_return().

◆ redirect_stdout_stderr()

void redirect_stdout_stderr ( const char *  file,
bool  append 
)

Definition at line 515 of file error.c.

References ASSERT, gc_free(), gc_new(), M_ERR, M_ERRNO, M_WARN, msg, msgfp, orig_stderr, std_redir, and wide_string().

Referenced by add_option().

◆ reset_check_status()

void reset_check_status ( void  )

Definition at line 630 of file error.c.

References x_cs_info_level, and x_cs_verbose_level.

Referenced by init_static().

◆ set_check_status()

void set_check_status ( unsigned int  info_level,
unsigned int  verbose_level 
)

Definition at line 637 of file error.c.

References x_cs_info_level, and x_cs_verbose_level.

Referenced by init_verb_mute().

◆ set_check_status_error_delay()

static void set_check_status_error_delay ( unsigned int  milliseconds)
inlinestatic

Definition at line 286 of file error.h.

References x_cs_err_delay_ms.

Referenced by init_instance().

◆ set_debug_level()

bool set_debug_level ( const int  level,
const unsigned int  flags 
)

Definition at line 105 of file error.c.

References constrain_int(), SDL_CONSTRAIN, and x_debug_level.

Referenced by add_option(), init_verb_mute(), and man_dispatch_command().

◆ set_machine_readable_output()

void set_machine_readable_output ( bool  parsable)

Definition at line 155 of file error.c.

References machine_readable_output.

Referenced by add_option().

◆ set_mute_cutoff()

bool set_mute_cutoff ( const int  cutoff)

Definition at line 123 of file error.c.

References mute_cutoff.

Referenced by init_verb_mute(), and man_dispatch_command().

◆ set_suppress_timestamps()

void set_suppress_timestamps ( bool  suppressed)

Definition at line 149 of file error.c.

References suppress_timestamps.

Referenced by add_option().

◆ strerror_win32()

const char* strerror_win32 ( DWORD  errnum,
struct gc_arena gc 
)

◆ x_check_status()

void x_check_status ( int  status,
const char *  description,
struct link_socket sock,
struct tuntap tt 
)

◆ x_msg()

void x_msg ( const unsigned int  flags,
const char *  format,
  ... 
)

Definition at line 213 of file error.c.

◆ x_msg_va()

void x_msg_va ( const unsigned int  flags,
const char *  format,
va_list  arglist 
)

Definition at line 234 of file error.c.

Variable Documentation

◆ x_cs_err_delay_ms

unsigned int x_cs_err_delay_ms

Definition at line 627 of file error.c.

Referenced by set_check_status_error_delay(), and x_check_status().

◆ x_cs_info_level

unsigned int x_cs_info_level

Definition at line 625 of file error.c.

Referenced by reset_check_status(), set_check_status(), and x_check_status().

◆ x_cs_verbose_level

unsigned int x_cs_verbose_level

Definition at line 626 of file error.c.

Referenced by check_status(), reset_check_status(), set_check_status(), and x_check_status().

◆ x_debug_level

unsigned int x_debug_level

Definition at line 52 of file error.c.

Referenced by check_debug_level().

◆ x_msg_line_num

int x_msg_line_num

Definition at line 210 of file error.c.

◆ x_msg_prefix

const char* x_msg_prefix

Definition at line 722 of file error.c.

Referenced by msg_get_prefix(), and msg_set_prefix().

◆ x_msg_virtual_output

const struct virtual_output* x_msg_virtual_output

Definition at line 728 of file error.c.

Referenced by msg_get_virtual_output(), and msg_set_virtual_output().