aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2009-04-13 03:30:30 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2009-04-13 03:30:30 +0000
commitb16cd4d28cdf9bf16fdbe892b82b88f467088509 (patch)
treed0dcb3e5e843f3ce8b2b39871094c3aaa777bce9
parentAllow "management-client" directive to be used (diff)
downloadopenvpn-b16cd4d28cdf9bf16fdbe892b82b88f467088509.tar.xz
Added errors-to-stderr option. When enabled, fatal errors
that result in the termination of the daemon will be written to stderr. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@4131 e7ae566f-a301-0410-adde-c780ea21d3b5
-rw-r--r--error.c18
-rw-r--r--error.h9
-rw-r--r--options.c7
3 files changed, 28 insertions, 6 deletions
diff --git a/error.c b/error.c
index c72f5bc..6314de4 100644
--- a/error.c
+++ b/error.c
@@ -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)
diff --git a/error.h b/error.h
index b949efc..143b73a 100644
--- a/error.h
+++ b/error.h
@@ -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)
diff --git a/options.c b/options.c
index f2c7da8..cd73d92 100644
--- a/options.c
+++ b/options.c
@@ -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);