]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Added errors-to-stderr option. When enabled, fatal errors
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Mon, 13 Apr 2009 03:30:30 +0000 (03:30 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Mon, 13 Apr 2009 03:30:30 +0000 (03:30 +0000)
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

error.c
error.h
options.c

diff --git a/error.c b/error.c
index c72f5bc1a47282a605dc20424135884db8eee74e..6314de4af905b612245a707802534edfd1d6dd56 100644 (file)
--- 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 b949efc65106f1e4fa25914b199bc02d1a195067..143b73ac66bb7e39b51ff55995b0dc82bc66099e 100644 (file)
--- 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)
index f2c7da86c9e5a4466afbf78cd7024ca0e1a12648..cd73d9226eb22297b4a959ef808a3000883f58ba 100644 (file)
--- 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);