~percona-dev/percona-server/release-5.1.49-12-rnt-pre

« back to all changes in this revision

Viewing changes to rnt-mysql-syslog.patch

  • Committer: Oleg Tsarev
  • Date: 2010-08-26 04:11:13 UTC
  • mfrom: (107.1.3 10777_rnt)
  • Revision ID: oleg.tsarev@percona.com-20100826041113-f2pd3inu2ww1yw2v
propogateĀ lp:percona-server

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
diff -Nur a/client/client_priv.h b/client/client_priv.h
2
 
--- a/client/client_priv.h      2010-08-08 14:12:42.229338865 +0400
3
 
+++ b/client/client_priv.h      2010-08-08 14:12:43.068089277 +0400
4
 
@@ -90,6 +90,7 @@
5
 
   OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT,
6
 
   OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
7
 
   OPT_WRITE_BINLOG, OPT_DUMP_DATE,
8
 
+  OPT_SYSLOG,
9
 
   OPT_FIRST_SLAVE,
10
 
   OPT_ALL,
11
 
   OPT_MAX_CLIENT_OPTION,
12
 
diff -Nur a/client/mysql.cc b/client/mysql.cc
13
 
--- a/client/mysql.cc   2010-08-08 14:12:42.229338865 +0400
14
 
+++ b/client/mysql.cc   2010-08-08 14:12:43.488088866 +0400
15
 
@@ -43,6 +43,9 @@
16
 
 #include "my_readline.h"
17
 
 #include <signal.h>
18
 
 #include <violite.h>
19
 
+#ifndef __WIN__
20
 
+#include "syslog.h"
21
 
+#endif
22
 
 
23
 
 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
24
 
 #include <locale.h>
25
 
@@ -154,7 +157,7 @@
26
 
               default_charset_used= 0, opt_secure_auth= 0,
27
 
                default_pager_set= 0, opt_sigint_ignore= 0,
28
 
                show_warnings= 0, executing_query= 0, interrupted_query= 0,
29
 
-               ignore_spaces= 0;
30
 
+               opt_syslog=0, ignore_spaces= 0;
31
 
 static my_bool debug_info_flag, debug_check_flag;
32
 
 static my_bool column_types_flag;
33
 
 static my_bool preserve_comments= 0;
34
 
@@ -209,6 +212,7 @@
35
 
 void tee_fputs(const char *s, FILE *file);
36
 
 void tee_puts(const char *s, FILE *file);
37
 
 void tee_putc(int c, FILE *file);
38
 
+void write_syslog(char *line);
39
 
 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
40
 
 /* The names of functions that actually do the manipulation. */
41
 
 static int get_options(int argc,char **argv);
42
 
@@ -1568,6 +1572,10 @@
43
 
   {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
44
 
     &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
45
 
     0, 0, 0, 0, 0, 0},
46
 
+#ifndef __WIN__
47
 
+  {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
48
 
+   NO_ARG, 0, 0, 0, 0, 0, 0},
49
 
+#endif
50
 
   { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
51
 
 };
52
 
 
53
 
@@ -1691,6 +1699,12 @@
54
 
                                     opt->name);
55
 
 #endif
56
 
     break;
57
 
+  case OPT_SYSLOG:
58
 
+    /*if (connect_flag == CLIENT_INTERACTIVE){
59
 
+      printf("Logging queries to syslog.\n");
60
 
+    }*/
61
 
+    opt_syslog = 1;
62
 
+    break;
63
 
   case OPT_SERVER_ARG:
64
 
 #ifdef EMBEDDED_LIBRARY
65
 
     /*
66
 
@@ -2067,6 +2081,39 @@
67
 
   DBUG_RETURN((COMMANDS *) 0);
68
 
 }
69
 
 
70
 
+void write_syslog(char *line){
71
 
+#ifndef __WIN__
72
 
+  char buff[901];
73
 
+  int i, buff_pos=0;
74
 
+  for (i=0;i < strlen(line); i++){
75
 
+    buff[buff_pos] = line[i];
76
 
+    buff_pos++;
77
 
+    if (buff_pos >= 900){
78
 
+      buff[900] = NULL;
79
 
+      buff_pos = 0;
80
 
+      syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
81
 
+             getenv("SUDO_USER") ? getenv("SUDO_USER") :
82
 
+             getenv("USER") ? getenv("USER") : "--",
83
 
+             current_user ? current_user : "--",
84
 
+             mysql_thread_id(&mysql),
85
 
+             current_host ? current_host : "--",
86
 
+             current_db ? current_db : "--",
87
 
+             buff);
88
 
+    }
89
 
+  }
90
 
+  if (buff_pos > 0){
91
 
+    buff[buff_pos] = NULL;
92
 
+    syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
93
 
+           getenv("SUDO_USER") ? getenv("SUDO_USER") :
94
 
+           getenv("USER") ? getenv("USER") : "--",
95
 
+           current_user ? current_user : "--",
96
 
+           mysql_thread_id(&mysql),
97
 
+           current_host ? current_host : "--",
98
 
+           current_db ? current_db : "--",
99
 
+           buff);
100
 
+  }
101
 
+#endif
102
 
+}
103
 
 
104
 
 static bool add_line(String &buffer,char *line,char *in_string,
105
 
                      bool *ml_comment, bool truncated)
106
 
@@ -3038,6 +3085,11 @@
107
 
     fix_history(buffer);
108
 
   }
109
 
 #endif
110
 
+#ifndef __WIN__
111
 
+  if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
112
 
+    write_syslog(buffer->c_ptr());
113
 
+  }
114
 
+#endif
115
 
 
116
 
   buffer->length(0);
117