[Commits] Rev 2902: Ability to write commands to syslog added to console client. in file:///home/bell/maria/bzr/work-maria-5.2-perconaSyslog/

sanja at askmonty.org sanja at askmonty.org
Sun Jan 16 23:09:46 EET 2011


At file:///home/bell/maria/bzr/work-maria-5.2-perconaSyslog/

------------------------------------------------------------
revno: 2902
revision-id: sanja at askmonty.org-20110116210945-odzbm9cnm6hhzrp5
parent: sergii at pisem.net-20101220181924-36y30fgi1soarmdo
committer: sanja at askmonty.org
branch nick: work-maria-5.2-perconaSyslog
timestamp: Sun 2011-01-16 23:09:45 +0200
message:
  Ability to write commands to syslog added to console client.
-------------- next part --------------
=== modified file 'client/client_priv.h'
--- a/client/client_priv.h	2010-03-29 15:13:53 +0000
+++ b/client/client_priv.h	2011-01-16 21:09:45 +0000
@@ -90,6 +90,9 @@ enum options_client
   OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
   OPT_WRITE_BINLOG, OPT_DUMP_DATE,
   OPT_ABORT_SOURCE_ON_ERROR,
+#ifndef __WIN__
+  OPT_SYSLOG,
+#endif
   OPT_FIRST_SLAVE,
   OPT_ALL,
   OPT_REWRITE_DB,

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2010-11-30 21:11:03 +0000
+++ b/client/mysql.cc	2011-01-16 21:09:45 +0000
@@ -44,6 +44,9 @@ and you are welcome to modify and redist
 #include "my_readline.h"
 #include <signal.h>
 #include <violite.h>
+#ifndef __WIN__
+#include "syslog.h"
+#endif
 
 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
 #include <locale.h>
@@ -152,7 +155,7 @@ static my_bool ignore_errors=0,wait_flag
 	       default_charset_used= 0, opt_secure_auth= 0,
                default_pager_set= 0, opt_sigint_ignore= 0,
                show_warnings= 0, executing_query= 0,
-               ignore_spaces= 0;
+               ignore_spaces= 0, opt_syslog= 0;
 static my_bool debug_info_flag, debug_check_flag, batch_abort_on_error;
 static my_bool column_types_flag;
 static my_bool preserve_comments= 0;
@@ -210,6 +213,9 @@ void tee_fprintf(FILE *file, const char
 void tee_fputs(const char *s, FILE *file);
 void tee_puts(const char *s, FILE *file);
 void tee_putc(int c, FILE *file);
+#ifndef __WIN__
+void write_syslog(String *buffer);
+#endif
 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
 /* The names of functions that actually do the manipulation. */
 static int get_options(int argc,char **argv);
@@ -1583,6 +1589,10 @@ static struct my_option my_long_options[
     "Default authentication client-side plugin to use.",
    (uchar**) &opt_default_auth, (uchar**) &opt_default_auth, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#ifndef __WIN__
+  {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+#endif
   { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 };
 
@@ -1706,6 +1716,11 @@ get_one_option(int optid, const struct m
                                     opt->name);
 #endif
     break;
+#ifndef __WIN__
+  case OPT_SYSLOG:
+    opt_syslog = 1;
+    break;
+#endif
   case OPT_SERVER_ARG:
 #ifdef EMBEDDED_LIBRARY
     /*
@@ -2085,6 +2100,33 @@ static COMMANDS *find_command(char *name
   DBUG_RETURN((COMMANDS *) 0);
 }
 
+#define MAX_SYSLOG_MESSAGE 900
+
+#ifndef __WIN__
+void write_syslog(String *line)
+{
+  uint length;
+  uint used_length;
+  char *ptr= line->c_ptr_safe();
+
+  for (length= line->length();
+       length;
+       length-= used_length, ptr+= used_length)
+  {
+    used_length= min(MAX_SYSLOG_MESSAGE, length);
+    syslog(LOG_INFO,
+           "SYSTEM_USER: '%s'  MYSQL_USER: '%s'  CONNECTION_ID: %lu  "
+           "DB_SERVER: '%s', DB: '%s', QUERY: '%.*s'",
+           getenv("SUDO_USER") ? getenv("SUDO_USER") :
+           getenv("USER") ? getenv("USER") : "--",
+           current_user ? current_user : "--",
+           mysql_thread_id(&mysql),
+           current_host ? current_host : "--",
+           current_db ? current_db : "--",
+           used_length, ptr);
+  }
+}
+#endif
 
 static bool add_line(String &buffer,char *line,char *in_string,
                      bool *ml_comment, bool truncated)
@@ -3056,6 +3098,10 @@ com_go(String *buffer,char *line __attri
     fix_history(buffer);
   }
 #endif
+#ifndef __WIN__
+  if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE)
+    write_syslog(buffer);
+#endif
 
   buffer->length(0);
 



More information about the commits mailing list