]> git.pld-linux.org Git - packages/mysql.git/blame - mysql_syslog.patch
- more mysqld.conf changes: skip-locking, default-character-set
[packages/mysql.git] / mysql_syslog.patch
CommitLineData
b4e1fa2c
AM
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!
8diff -ruN a/client/client_priv.h b/client/client_priv.h
9--- a/client/client_priv.h 2011-01-13 18:35:59.000000000 +0300
10+++ b/client/client_priv.h 2011-01-13 18:38:21.000000000 +0300
11@@ -85,6 +85,9 @@
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+#ifndef __WIN__
16+ OPT_SYSLOG,
17+#endif
18 OPT_PLUGIN_DIR,
19 OPT_DEFAULT_PLUGIN,
20 OPT_MAX_CLIENT_OPTION
21diff -ruN a/client/mysql.cc b/client/mysql.cc
22--- a/client/mysql.cc 2010-12-03 20:58:26.000000000 +0300
23+++ b/client/mysql.cc 2011-01-13 18:38:21.000000000 +0300
24@@ -38,6 +38,11 @@
25 #include "my_readline.h"
26 #include <signal.h>
27 #include <violite.h>
28+#ifndef __WIN__
29+#include "syslog.h"
30+#endif
31+
32+#define MAX_SYSLOG_MESSAGE 900
33
34 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
35 #include <locale.h>
36@@ -140,7 +145,7 @@
37 default_pager_set= 0, opt_sigint_ignore= 0,
38 auto_vertical_output= 0,
39 show_warnings= 0, executing_query= 0, interrupted_query= 0,
40- ignore_spaces= 0;
41+ ignore_spaces= 0, opt_syslog= 0;
42 static my_bool debug_info_flag, debug_check_flag;
43 static my_bool column_types_flag;
44 static my_bool preserve_comments= 0;
45@@ -198,6 +203,7 @@
46 void tee_fputs(const char *s, FILE *file);
47 void tee_puts(const char *s, FILE *file);
48 void tee_putc(int c, FILE *file);
49+void write_syslog(String *buffer);
50 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
51 /* The names of functions that actually do the manipulation. */
52 static int get_options(int argc,char **argv);
53@@ -1561,6 +1567,10 @@
54 {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
55 &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
56 0, 0, 0, 0, 0, 0},
57+#ifndef __WIN__
58+ {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
59+ NO_ARG, 0, 0, 0, 0, 0, 0},
60+#endif
61 {"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
62 (uchar**) &opt_plugin_dir, (uchar**) &opt_plugin_dir, 0,
63 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
64@@ -1665,6 +1675,11 @@
65 opt->name);
66 #endif
67 break;
68+#ifndef __WIN__
69+ case OPT_SYSLOG:
70+ opt_syslog = 1;
71+ break;
72+#endif
73 case OPT_SERVER_ARG:
74 #ifdef EMBEDDED_LIBRARY
75 /*
76@@ -2014,6 +2029,40 @@
77 DBUG_RETURN((COMMANDS *) 0);
78 }
79
80+void write_syslog(String *line){
81+#ifndef __WIN__
82+ uint length= line->length();
83+ uint chunk_len= min(MAX_SYSLOG_MESSAGE, length);
84+ char *ptr= line->c_ptr_safe();
85+ char buff[MAX_SYSLOG_MESSAGE + 1];
86+
87+ for (;
88+ length;
89+ length-= chunk_len, ptr+= chunk_len, chunk_len= min(MAX_SYSLOG_MESSAGE,
90+ length))
91+ {
92+ char *str;
93+ if (length == chunk_len)
94+ str= ptr; // last chunk => skip copy
95+ else
96+ {
97+ memcpy(buff, ptr, chunk_len);
98+ buff[chunk_len]= '\0';
99+ str= buff;
100+ }
101+ syslog(LOG_INFO,
102+ "SYSTEM_USER:'%s', MYSQL_USER:'%s', CONNECTION_ID:%lu, "
103+ "DB_SERVER:'%s', DB:'%s', QUERY:'%s'",
104+ getenv("SUDO_USER") ? getenv("SUDO_USER") :
105+ getenv("USER") ? getenv("USER") : "--",
106+ current_user ? current_user : "--",
107+ mysql_thread_id(&mysql),
108+ current_host ? current_host : "--",
109+ current_db ? current_db : "--",
110+ str);
111+ }
112+#endif
113+}
114
115 static bool add_line(String &buffer,char *line,char *in_string,
116 bool *ml_comment, bool truncated)
d8778560 117@@ -2990,6 +3039,11 @@
b4e1fa2c
AM
118 fix_history(buffer);
119 }
120 #endif
121+#ifndef __WIN__
122+ if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
123+ write_syslog(buffer);
124+ }
125+#endif
126
127 buffer->length(0);
128
This page took 0.043263 seconds and 4 git commands to generate.