]> git.pld-linux.org Git - packages/mysql.git/blob - mysql_syslog.patch
cosmetics: make unix socket mouse selectable in terminal
[packages/mysql.git] / mysql_syslog.patch
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 --- a/client/client_priv.h
9 +++ b/client/client_priv.h
10 @@ -85,6 +85,9 @@
11    OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
12    OPT_WRITE_BINLOG, OPT_DUMP_DATE,
13    OPT_INIT_COMMAND,
14 +#ifndef __WIN__
15 +  OPT_SYSLOG,
16 +#endif
17    OPT_PLUGIN_DIR,
18    OPT_DEFAULT_AUTH,
19    OPT_DEFAULT_PLUGIN,
20 --- a/client/mysql.cc
21 +++ b/client/mysql.cc
22 @@ -40,6 +40,11 @@
23  #include "my_readline.h"
24  #include <signal.h>
25  #include <violite.h>
26 +#ifndef __WIN__
27 +#include "syslog.h"
28 +#endif
29 +
30 +#define MAX_SYSLOG_MESSAGE 900
31  
32  #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
33  #include <locale.h>
34 @@ -142,7 +147,7 @@
35                 default_pager_set= 0, opt_sigint_ignore= 0,
36                 auto_vertical_output= 0,
37                 show_warnings= 0, executing_query= 0, interrupted_query= 0,
38 -               ignore_spaces= 0;
39 +               ignore_spaces= 0, opt_syslog= 0;
40  static my_bool debug_info_flag, debug_check_flag;
41  static my_bool column_types_flag;
42  static my_bool preserve_comments= 0;
43 @@ -200,6 +205,7 @@
44  void tee_fputs(const char *s, FILE *file);
45  void tee_puts(const char *s, FILE *file);
46  void tee_putc(int c, FILE *file);
47 +void write_syslog(String *buffer);
48  static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
49  /* The names of functions that actually do the manipulation. */
50  static int get_options(int argc,char **argv);
51 @@ -1565,6 +1571,10 @@
52    {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
53      &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
54      0, 0, 0, 0, 0, 0},
55 +#ifndef __WIN__
56 +  {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
57 +   NO_ARG, 0, 0, 0, 0, 0, 0},
58 +#endif
59    {"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
60      &opt_plugin_dir, &opt_plugin_dir, 0,
61     GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
62 @@ -1669,6 +1679,11 @@
63                                      opt->name);
64  #endif
65      break;
66 +#ifndef __WIN__
67 +  case OPT_SYSLOG:
68 +    opt_syslog = 1;
69 +    break;
70 +#endif
71    case OPT_SERVER_ARG:
72  #ifdef EMBEDDED_LIBRARY
73      /*
74 @@ -2022,6 +2037,40 @@
75    DBUG_RETURN((COMMANDS *) 0);
76  }
77  
78 +void write_syslog(String *line){
79 +#ifndef __WIN__
80 +  uint length= line->length();
81 +  uint chunk_len= min(MAX_SYSLOG_MESSAGE, length);
82 +  char *ptr= line->c_ptr_safe();
83 +  char buff[MAX_SYSLOG_MESSAGE + 1];
84 +
85 +  for (;
86 +       length;
87 +       length-= chunk_len, ptr+= chunk_len, chunk_len= min(MAX_SYSLOG_MESSAGE,
88 +                                                           length))
89 +  {
90 +    char *str;
91 +    if (length == chunk_len)
92 +      str= ptr;                                 // last chunk => skip copy
93 +    else
94 +    {
95 +      memcpy(buff, ptr, chunk_len);
96 +      buff[chunk_len]= '\0';
97 +      str= buff;
98 +    }
99 +    syslog(LOG_INFO,
100 +           "SYSTEM_USER:'%s', MYSQL_USER:'%s', CONNECTION_ID:%lu, "
101 +           "DB_SERVER:'%s', DB:'%s', QUERY:'%s'",
102 +           getenv("SUDO_USER") ? getenv("SUDO_USER") : 
103 +           getenv("USER") ? getenv("USER") : "--",
104 +           current_user ? current_user : "--",
105 +           mysql_thread_id(&mysql),
106 +           current_host ? current_host : "--",
107 +           current_db ? current_db : "--",
108 +           str);
109 +  }
110 +#endif
111 +}
112  
113  static bool add_line(String &buffer,char *line,char *in_string,
114                       bool *ml_comment, bool truncated)
115 @@ -2998,6 +3047,11 @@
116      fix_history(buffer);
117    }
118  #endif
119 +#ifndef __WIN__
120 +  if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
121 +    write_syslog(buffer);
122 +  }
123 +#endif
124  
125    buffer->length(0);
126  
This page took 0.197499 seconds and 3 git commands to generate.