diff options
-rw-r--r-- | error.c | 18 | ||||
-rw-r--r-- | error.h | 9 | ||||
-rw-r--r-- | options.c | 7 |
3 files changed, 28 insertions, 6 deletions
@@ -88,6 +88,10 @@ static FILE *msgfp; /* GLOBAL */ /* If true, we forked from main OpenVPN process */ static bool forked; /* GLOBAL */ +/* our default output targets */ +static FILE *default_out; /* GLOBAL */ +static FILE *default_err; /* GLOBAL */ + void msg_forked (void) { @@ -151,6 +155,8 @@ error_reset () mute_cutoff = 0; mute_count = 0; mute_category = 0; + default_out = OPENVPN_MSG_FP; + default_err = OPENVPN_MSG_FP; #ifdef OPENVPN_DEBUG_COMMAND_LINE msgfp = fopen (OPENVPN_DEBUG_FILE, "w"); @@ -161,15 +167,21 @@ error_reset () #endif } +void +errors_to_stderr (void) +{ + default_err = OPENVPN_ERROR_FP; +} + /* * Return a file to print messages to before syslog is opened. */ FILE * -msg_fp() +msg_fp(const unsigned int flags) { FILE *fp = msgfp; if (!fp) - fp = OPENVPN_MSG_FP; + fp = (flags & (M_FATAL|M_USAGE_SMALL)) ? default_err : default_out; if (!fp) openvpn_exit (OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE); /* exit point */ return fp; @@ -305,7 +317,7 @@ void x_msg (const unsigned int flags, const char *format, ...) } else { - FILE *fp = msg_fp(); + FILE *fp = msg_fp(flags); const bool show_usec = check_debug_level (DEBUG_LEVEL_USEC_TIME); if ((flags & M_NOPREFIX) || suppress_timestamps) @@ -42,7 +42,8 @@ struct gc_arena; * Where should messages be printed before syslog is opened? * Not used if OPENVPN_DEBUG_COMMAND_LINE is defined. */ -#define OPENVPN_MSG_FP stdout +#define OPENVPN_MSG_FP stdout +#define OPENVPN_ERROR_FP stderr /* * Exit status codes @@ -183,6 +184,10 @@ void x_msg (const unsigned int flags, const char *format, ...) */ void error_reset (void); + +/* route errors to stderr that would normally go to stdout */ +void errors_to_stderr (void); + void set_suppress_timestamps (bool suppressed); #define SDL_CONSTRAIN (1<<0) @@ -198,7 +203,7 @@ const char *msg_flags_string (const unsigned int flags, struct gc_arena *gc); /* * File to print messages to before syslog is opened. */ -FILE *msg_fp(void); +FILE *msg_fp(const unsigned int flags); /* Fatal logic errors */ #define ASSERT(x) do { if (!(x)) assert_failed(__FILE__, __LINE__); } while (false) @@ -2669,7 +2669,7 @@ auth_retry_print (void) static void usage (void) { - FILE *fp = msg_fp(); + FILE *fp = msg_fp(0); #ifdef ENABLE_SMALL @@ -3859,6 +3859,11 @@ add_option (struct options *options, VERIFY_PERMISSION (OPT_P_MESSAGES); options->mute = positive_atoi (p[1]); } + else if (streq (p[0], "errors-to-stderr")) + { + VERIFY_PERMISSION (OPT_P_MESSAGES); + errors_to_stderr(); + } else if (streq (p[0], "status") && p[1]) { VERIFY_PERMISSION (OPT_P_GENERAL); |