diff options
| author | Arne Schwabe <arne@rfc2549.org> | 2013-09-27 22:37:17 +0200 | 
|---|---|---|
| committer | Arne Schwabe <arne@rfc2549.org> | 2013-09-27 22:37:17 +0200 | 
| commit | 4d9f6e5358b97ab104bc6c26b862ab290161568f (patch) | |
| tree | b0fb4648aa6c6a17325c73ecc9413a8811a3ccae /openvpn | |
| parent | 9ecc730cebfeff8b5fae9d4fd1db7cf1f32da2b0 (diff) | |
Implement parse-output in OpenVPN
--HG--
extra : rebase_source : 5b85b83ec885ba2af6e00092af6f62ef1c0520c0
Diffstat (limited to 'openvpn')
| -rw-r--r-- | openvpn/doc/openvpn.8 | 6 | ||||
| -rw-r--r-- | openvpn/src/openvpn/error.c | 29 | ||||
| -rw-r--r-- | openvpn/src/openvpn/error.h | 2 | ||||
| -rw-r--r-- | openvpn/src/openvpn/manage.h | 2 | ||||
| -rw-r--r-- | openvpn/src/openvpn/options.c | 8 | ||||
| -rw-r--r-- | openvpn/src/openvpn/options.h | 1 | 
6 files changed, 46 insertions, 2 deletions
diff --git a/openvpn/doc/openvpn.8 b/openvpn/doc/openvpn.8 index 72a85a90..55152c1c 100644 --- a/openvpn/doc/openvpn.8 +++ b/openvpn/doc/openvpn.8 @@ -2261,6 +2261,12 @@ otherwise would be prepended. In particular, this applies to  log messages sent to stdout.  .\"*********************************************************  .TP +.B \-\-parsable-output +Always write timestamps and message flags to log messages, even when they +otherwise would not be prefixed. In particular, this applies to +log messages sent to stdout. +.\"********************************************************* +.TP  .B \-\-writepid file  Write OpenVPN's main process ID to  .B file. 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, diff --git a/openvpn/src/openvpn/error.h b/openvpn/src/openvpn/error.h index 27c48b69..5571bfdb 100644 --- a/openvpn/src/openvpn/error.h +++ b/openvpn/src/openvpn/error.h @@ -194,6 +194,8 @@ void error_reset (void);  void errors_to_stderr (void);  void set_suppress_timestamps (bool suppressed); +void set_parsable_output (bool parsable); +  #define SDL_CONSTRAIN (1<<0)  bool set_debug_level (const int level, const unsigned int flags); diff --git a/openvpn/src/openvpn/manage.h b/openvpn/src/openvpn/manage.h index 962b5bc4..dc3ade10 100644 --- a/openvpn/src/openvpn/manage.h +++ b/openvpn/src/openvpn/manage.h @@ -34,7 +34,7 @@  #define MANAGEMENT_VERSION                      1  #define MANAGEMENT_N_PASSWORD_RETRIES           3 -#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE   100 +#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE   200  #define MANAGEMENT_ECHO_BUFFER_SIZE           100  #define MANAGEMENT_STATE_BUFFER_SIZE          100 diff --git a/openvpn/src/openvpn/options.c b/openvpn/src/openvpn/options.c index d1c5583f..66fb8962 100644 --- a/openvpn/src/openvpn/options.c +++ b/openvpn/src/openvpn/options.c @@ -342,6 +342,7 @@ static const char usage_message[] =    "--log file      : Output log to file which is created/truncated on open.\n"    "--log-append file : Append log to file, or create file if nonexistent.\n"    "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n" +  "--parsable-output : Always log timestamp, message flags to stdout/stderr.\n"    "--writepid file : Write main process ID to file.\n"    "--nice n        : Change process priority (>0 = lower, <0 = higher).\n"    "--echo [parms ...] : Echo parameters to log output.\n" @@ -1510,6 +1511,7 @@ show_settings (const struct options *o)    SHOW_INT (inetd);    SHOW_BOOL (log);    SHOW_BOOL (suppress_timestamps); +  SHOW_BOOL (parsable_output);    SHOW_INT (nice);    SHOW_INT (verbosity);    SHOW_INT (mute); @@ -4658,6 +4660,12 @@ add_option (struct options *options,        options->suppress_timestamps = true;        set_suppress_timestamps(true);      } +  else if (streq (p[0], "parsable-output")) +    { +      VERIFY_PERMISSION (OPT_P_GENERAL); +      options->parsable_output = true; +      set_parsable_output(true); +    }    else if (streq (p[0], "log-append") && p[1])      {        VERIFY_PERMISSION (OPT_P_GENERAL); diff --git a/openvpn/src/openvpn/options.h b/openvpn/src/openvpn/options.h index 86760bbf..99877da7 100644 --- a/openvpn/src/openvpn/options.h +++ b/openvpn/src/openvpn/options.h @@ -304,6 +304,7 @@ struct options    bool log;    bool suppress_timestamps; +  bool parsable_output;    int nice;    int verbosity;    int mute;  | 
