diff options
Diffstat (limited to 'openvpn/src/openvpn/error.c')
| -rw-r--r-- | openvpn/src/openvpn/error.c | 29 | 
1 files changed, 28 insertions, 1 deletions
diff --git a/openvpn/src/openvpn/error.c b/openvpn/src/openvpn/error.c index 98611a1b..106213db 100644 --- a/openvpn/src/openvpn/error.c +++ b/openvpn/src/openvpn/error.c @@ -86,6 +86,10 @@ static bool std_redir;      /* GLOBAL */  /* Should messages be written to the syslog? */  static bool use_syslog;     /* GLOBAL */ +/* Should stdout/stderr be be parsable and always be prefixed with time + * and message flags */ +static bool parsable_output;   /* GLOBAL */ +  /* Should timestamps be included on messages to stdout/stderr? */  static bool suppress_timestamps; /* GLOBAL */ @@ -159,10 +163,18 @@ set_suppress_timestamps (bool suppressed)  }  void +set_parsable_output (bool parsable) +{ +  parsable_output = parsable; +} + + +void  error_reset ()  {    use_syslog = std_redir = false;    suppress_timestamps = false; +  parsable_output = false;    x_debug_level = 1;    mute_cutoff = 0;    mute_count = 0; @@ -334,7 +346,22 @@ void x_msg_va (const unsigned int flags, const char *format, va_list arglist)  	  FILE *fp = msg_fp(flags);  	  const bool show_usec = check_debug_level (DEBUG_LEVEL_USEC_TIME); -	  if ((flags & M_NOPREFIX) || suppress_timestamps) +	  if (parsable_output) +	    { +	      struct timeval tv; +	      gettimeofday (&tv, NULL); + +	      fprintf (fp, "%ld.%06d %x %s%s%s%s", +		       tv.tv_sec, +		       tv.tv_usec, +		       flags, +		       prefix, +		       prefix_sep, +		       m1, +		       (flags&M_NOLF) ? "" : "\n"); + +	    } +	  else if ((flags & M_NOPREFIX) || suppress_timestamps)  	    {  	      fprintf (fp, "%s%s%s%s",  		       prefix,  | 
