MySQL  8.0.17
Source Code Documentation
log_builtins_filter_imp.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef LOG_FILTER_INTERNAL_H
24 #define LOG_FILTER_INTERNAL_H
26 
28  public:
29  /**
30  Initialize built-in log filter.
31  */
32  static void init();
33 
34  /**
35  De-initialize built-in log filter.
36  */
37  static void deinit();
38 
39  public: /* Service Implementations */
40  /**
41  Create a new set of filter rules.
42 
43  @param tag identifying tag of the rule-set creator
44  @param count number of rules to allocate
45 
46  @retval a pointer to a ruleset structure, or nullptr on failure
47  */
49  (log_filter_tag * tag, size_t count));
50 
51  /**
52  Lock and get the filter rules.
53 
54  @param ruleset a ruleset (usually allocated with filter_ruleset_new())
55  @param locktype LOG_BUILTINS_LOCK_SHARED lock for reading
56  LOG_BUILTINS_LOCK_EXCLUSIVE lock for writing
57 
58  @retval 0 lock acquired
59  @retval !0 failed to acquire lock
60  */
62  (log_filter_ruleset * ruleset,
63  log_builtins_filter_lock locktype));
64 
65  /**
66  Release lock on filter rules.
67 
68  @param ruleset a ruleset (usually allocated with filter_ruleset_new())
69  */
71  (log_filter_ruleset * ruleset));
72 
73  /**
74  Drop an entire filter rule-set. Must hold lock.
75 
76  @param ruleset a ruleset * (usually allocated with filter_ruleset_new())
77  */
79  (log_filter_ruleset * ruleset));
80 
81  /**
82  Free an entire filter rule-set. Must hold lock. Lock will be destroyed.
83 
84  @param ruleset a ruleset * (usually allocated with filter_ruleset_new())
85  the pointer pointed to will be a nullptr on return.
86  */
88  (log_filter_ruleset * *ruleset));
89 
90  /**
91  Move rules from one ruleset to another. Origin will be empty afterwards.
92 
93  @param from source ruleset
94  @param to destination ruleset
95  */
98 
99  /**
100  Initialize a new rule.
101  This clears the first unused rule. It does not update the rules
102  count; this is for the caller to do if it succeeds in setting up
103  the rule to its satisfaction. If the caller fails, it should
104  log_builtins_filter_rule_free() the incomplete rule.
105 
106  @param ruleset a ruleset (usually allocated with filter_ruleset_new())
107 
108  @retval nullptr could not initialize rule. Do not call rule_free.
109  @retval !nullptr the address of the rule. fill in. on success,
110  caller must increase rule count. on failure,
111  it must call rule_free.
112  */
113  static DEFINE_METHOD(void *, filter_rule_init,
114  (log_filter_ruleset * ruleset));
115 
116  /**
117  Apply all matching rules from a filter rule set to a given log line.
118 
119  @param ruleset a ruleset (usually allocated with filter_ruleset_new())
120  @param ll the current log line
121 
122  @retval int number of matched rules
123  */
124  static DEFINE_METHOD(int, filter_run,
125  (log_filter_ruleset * ruleset, log_line *ll));
126 };
127 
129  public:
130  /**
131  Initialize built-in log filter debug functionality.
132  */
133  static void init();
134 
135  /**
136  De-initialize built-in log filter debug functionality.
137  */
138  static void deinit();
139 
140  public: /* Service Implementations */
141  /**
142  Get filter rules used in built-in filter. For debug purposes only.
143  Third party code should not use this, nor rely on this API to be stable.
144 
145  @retval a pointer to a ruleset structure, or nullptr
146  */
148 };
149 
150 /**
151  Deinitialize filtering engine.
152 
153  @retval 0 Success!
154  @retval -1 De-initialize? Filter wasn't even initialized!
155 */
157 
158 /**
159  Initialize filtering engine.
160  We need to do this early, before the component system is up.
161 
162  @retval 0 Success!
163  @retval -1 Couldn't initialize ruleset lock
164  @retval -2 Filter was already initialized?
165 */
167 
168 /**
169  Apply all matching rules from a filter rule set to a given log line.
170 
171  @param ruleset the rule-set to apply to the event
172  @param ll the current log line
173 
174  @retval int number of matched rules
175 */
177 
178 #ifdef MYSQL_SERVER
179 
180 /**
181  This is part of the 5.7 emulation:
182  If --log_error_verbosity is changed, we generate an
183  artificial filter rule from it here.
184 
185  For this filtering to be active, @@global.log_error_services
186  has to feature "log_filter_internal", as it does by default.
187  When that is the case, one or both of log_error_verbosity and
188  log_error_suppression_list (see below) may be used.
189  Only one of "log_filter_internal" and "log_filter_dragnet"
190  should be used at a time.
191 
192  @param verbosity log_error_verbosity style, range(1,3)
193  1:errors, 2:+=warnings, 3:+=notes
194 
195  @retval 0: success
196  @retval !0: failure
197 */
198 int log_builtins_filter_update_verbosity(int verbosity);
199 
200 /**
201  @@global.log_error_suppression_list accepts a comma-separated
202  list of error-codes that should not be included in the error-log.
203  Events with a severity of System or Error can not be filtered
204  in this way and will always be forwarded to the log-sinks.
205 
206  This provides simple filtering for cases where the flexibility
207  of the loadable filter-language is not needed. (The same engine
208  is used however, just with a more limited interface.)
209 
210  For this filtering to be active, @@global.log_error_services has
211  to feature "log_filter_internal", as it does by default. When that
212  is the case, one or both of log_error_verbosity and this variable
213  may be used. Only one of "log_filter_internal" and "log_filter_dragnet"
214  should be used at a time.
215 
216  The semantics follow that of our system variables; that is to say,
217  when called with update==false, the function acts as a check-function
218  that validates the entire list given to it; when called with
219  update==true, it creates filter-rules from the list items. This way,
220  we either create all rules, or no rules, rather than ending up with
221  an incomplete rule-set when we encounter a problem in the input.
222 
223  The return value encodes the location in the argument where the
224  failure occurred, like so:
225  - if 0 is returned, no issues were detected
226  - if a value less than zero is returned, -(retval + 1) is the
227  byte position (counting from 0) in the list argument at
228  which point the failure was detected
229 
230  @param list list of error-codes that should not appear
231  in the error-log
232  @param update false: verify list only
233  true: create filtering rules from suppression list
234 
235  @retval 0: success
236  @retval !0: failure (see above)
237 */
239 
240 #endif /* MYSQL_SERVER */
241 
242 #endif /* LOG_FILTER_INTERNAL_H */
static void deinit()
De-initialize built-in log filter debug functionality.
static int filter_run(log_filter_ruleset *ruleset, log_line *ll) noexcept
Apply all matching rules from a filter rule set to a given log line.
Definition: log_builtins_filter.cc:1043
ssize_t count
Definition: memcached.c:386
static log_filter_ruleset * filter_debug_ruleset_get(void) noexcept
Get filter rules used in built-in filter.
Definition: log_builtins_filter.cc:1048
class udf_list * list
log_line ("log event")
Definition: log_builtins_imp.h:85
static void filter_ruleset_unlock(log_filter_ruleset *ruleset) noexcept
Release lock on filter rules.
Definition: log_builtins_filter.cc:1000
Definition: log_builtins_filter.h:149
#define DEFINE_METHOD(retval, name, args)
int log_builtins_filter_init()
Initialize filtering engine.
Definition: log_builtins_filter.cc:360
static int filter_ruleset_lock(log_filter_ruleset *ruleset, log_builtins_filter_lock locktype) noexcept
Lock and get the filter rules.
Definition: log_builtins_filter.cc:995
int log_builtins_filter_update_verbosity(int verbosity)
This is part of the 5.7 emulation: If –log_error_verbosity is changed, we generate an artificial fil...
Definition: log_builtins_filter.cc:764
static void filter_ruleset_drop(log_filter_ruleset *ruleset) noexcept
Drop an entire filter rule-set.
Definition: log_builtins_filter.cc:1005
static void init()
Initialize built-in log filter debug functionality.
Definition: log_builtins_filter_imp.h:128
enum enum_log_builtins_lock log_builtins_filter_lock
static uint update
Definition: myisamlog.cc:88
Definition: log_builtins_filter_imp.h:27
int log_builtins_filter_run(log_filter_ruleset *ruleset, log_line *ll)
Apply all matching rules from a filter rule set to a given log line.
Definition: log_builtins_filter.cc:639
Definition: log_builtins_filter.h:105
int log_builtins_filter_exit()
Deinitialize filtering engine.
Definition: log_builtins_filter.cc:334
static void deinit()
De-initialize built-in log filter.
static log_filter_ruleset * filter_ruleset_new(log_filter_tag *tag, size_t count) noexcept
Create a new set of filter rules.
Definition: log_builtins_filter.cc:989
static int filter_ruleset_move(log_filter_ruleset *from, log_filter_ruleset *to) noexcept
Move rules from one ruleset to another.
Definition: log_builtins_filter.cc:1015
static void init()
Initialize built-in log filter.
static void * filter_rule_init(log_filter_ruleset *ruleset) noexcept
Initialize a new rule.
Definition: log_builtins_filter.cc:1037
static void filter_ruleset_free(log_filter_ruleset **ruleset) noexcept
Free an entire filter rule-set.
Definition: log_builtins_filter.cc:1010
int log_builtins_filter_parse_suppression_list(char *list, bool update)
@global.log_error_suppression_list accepts a comma-separated list of error-codes that should not be i...
Definition: log_builtins_filter.cc:855