~sergei.glushchenko/percona-server/55-tp

« back to all changes in this revision

Viewing changes to mysql_syslog.patch

  • Committer: Oleg Tsarev
  • Date: 2010-12-09 18:30:58 UTC
  • Revision ID: oleg.tsarev@percona.com-20101209183058-1mq1qrgjjkz3qxof
propogate Oleg's patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# name       : mysql-syslog.patch
 
2
# introduced : 12
 
3
# maintainer : Oleg
 
4
#
 
5
#!!! notice !!!
 
6
# Any small change to this file in the main branch
 
7
# should be done or reviewed by the maintainer!
 
8
diff -ruN a/client/client_priv.h b/client/client_priv.h
 
9
--- a/client/client_priv.h      2010-08-08 14:12:42.229338865 +0400
 
10
+++ b/client/client_priv.h      2010-08-08 14:12:43.068089277 +0400
 
11
@@ -85,6 +85,7 @@
 
12
   OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
 
13
   OPT_WRITE_BINLOG, OPT_DUMP_DATE,
 
14
   OPT_INIT_COMMAND,
 
15
+  OPT_SYSLOG,
 
16
   OPT_PLUGIN_DIR,
 
17
   OPT_DEFAULT_PLUGIN,
 
18
   OPT_MAX_CLIENT_OPTION
 
19
diff -ruN a/client/mysql.cc b/client/mysql.cc
 
20
--- a/client/mysql.cc   2010-08-08 14:12:42.229338865 +0400
 
21
+++ b/client/mysql.cc   2010-08-08 14:12:43.488088866 +0400
 
22
@@ -38,6 +38,9 @@
 
23
 #include "my_readline.h"
 
24
 #include <signal.h>
 
25
 #include <violite.h>
 
26
+#ifndef __WIN__
 
27
+#include "syslog.h"
 
28
+#endif
 
29
 
 
30
 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
 
31
 #include <locale.h>
 
32
@@ -140,7 +143,7 @@
 
33
                default_pager_set= 0, opt_sigint_ignore= 0,
 
34
                auto_vertical_output= 0,
 
35
                show_warnings= 0, executing_query= 0, interrupted_query= 0,
 
36
-               ignore_spaces= 0;
 
37
+               opt_syslog=0, ignore_spaces= 0;
 
38
 static my_bool debug_info_flag, debug_check_flag;
 
39
 static my_bool column_types_flag;
 
40
 static my_bool preserve_comments= 0;
 
41
@@ -198,6 +201,7 @@
 
42
 void tee_fputs(const char *s, FILE *file);
 
43
 void tee_puts(const char *s, FILE *file);
 
44
 void tee_putc(int c, FILE *file);
 
45
+void write_syslog(char *line);
 
46
 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
 
47
 /* The names of functions that actually do the manipulation. */
 
48
 static int get_options(int argc,char **argv);
 
49
@@ -1561,6 +1565,10 @@
 
50
   {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
 
51
     &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
 
52
     0, 0, 0, 0, 0, 0},
 
53
+#ifndef __WIN__
 
54
+  {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
 
55
+   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
56
+#endif
 
57
   {"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
 
58
    (uchar**) &opt_plugin_dir, (uchar**) &opt_plugin_dir, 0,
 
59
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
60
@@ -1665,6 +1673,12 @@
 
61
                                     opt->name);
 
62
 #endif
 
63
     break;
 
64
+  case OPT_SYSLOG:
 
65
+    /*if (connect_flag == CLIENT_INTERACTIVE){
 
66
+      printf("Logging queries to syslog.\n");
 
67
+    }*/
 
68
+    opt_syslog = 1;
 
69
+    break;
 
70
   case OPT_SERVER_ARG:
 
71
 #ifdef EMBEDDED_LIBRARY
 
72
     /*
 
73
@@ -2014,6 +2028,39 @@
 
74
   DBUG_RETURN((COMMANDS *) 0);
 
75
 }
 
76
 
 
77
+void write_syslog(char *line){
 
78
+#ifndef __WIN__
 
79
+  char buff[901];
 
80
+  int i, buff_pos=0;
 
81
+  for (i=0;i < strlen(line); i++){
 
82
+    buff[buff_pos] = line[i];
 
83
+    buff_pos++;
 
84
+    if (buff_pos >= 900){
 
85
+      buff[900] = NULL;
 
86
+      buff_pos = 0;
 
87
+      syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
 
88
+             getenv("SUDO_USER") ? getenv("SUDO_USER") :
 
89
+             getenv("USER") ? getenv("USER") : "--",
 
90
+             current_user ? current_user : "--",
 
91
+             mysql_thread_id(&mysql),
 
92
+             current_host ? current_host : "--",
 
93
+             current_db ? current_db : "--",
 
94
+             buff);
 
95
+    }
 
96
+  }
 
97
+  if (buff_pos > 0){
 
98
+    buff[buff_pos] = NULL;
 
99
+    syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
 
100
+           getenv("SUDO_USER") ? getenv("SUDO_USER") :
 
101
+           getenv("USER") ? getenv("USER") : "--",
 
102
+           current_user ? current_user : "--",
 
103
+           mysql_thread_id(&mysql),
 
104
+           current_host ? current_host : "--",
 
105
+           current_db ? current_db : "--",
 
106
+           buff);
 
107
+  }
 
108
+#endif
 
109
+}
 
110
 
 
111
 static bool add_line(String &buffer,char *line,char *in_string,
 
112
                      bool *ml_comment, bool truncated)
 
113
@@ -2986,6 +3033,11 @@
 
114
     fix_history(buffer);
 
115
   }
 
116
 #endif
 
117
+#ifndef __WIN__
 
118
+  if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
 
119
+    write_syslog(buffer->c_ptr());
 
120
+  }
 
121
+#endif
 
122
 
 
123
   buffer->length(0);
 
124