summaryrefslogtreecommitdiffstats
path: root/error.c
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 /error.c
parent86f5c7c9d540096bcabf33b49303090e6638a99d (diff)
downloadopenvpn-b16cd4d28cdf9bf16fdbe892b82b88f467088509.tar.gz
openvpn-b16cd4d28cdf9bf16fdbe892b82b88f467088509.tar.xz
openvpn-b16cd4d28cdf9bf16fdbe892b82b88f467088509.zip
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
Diffstat (limited to 'error.c')
-rw-r--r--error.c18
1 files changed, 15 insertions, 3 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)