Merge lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370 into lp:percona-server/5.6
- 5.6-ps-bug1363370
- Merge into 5.6
Proposed by
Sergei Glushchenko
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Laurynas Biveinis | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 668 | ||||
Proposed branch: | lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370 | ||||
Merge into: | lp:percona-server/5.6 | ||||
Diff against target: |
1028 lines (+68/-427) 10 files modified
mysql-test/r/audit_log_rotate.result (+1/-0) mysql-test/t/audit_log_rotate-master.opt (+8/-0) mysql-test/t/audit_log_rotate.test (+29/-0) plugin/audit_log/audit_file.c (+0/-200) plugin/audit_log/audit_handler.h (+0/-116) plugin/audit_log/audit_syslog.c (+0/-91) plugin/audit_log/buffer.c (+7/-8) plugin/audit_log/buffer.h (+3/-1) plugin/audit_log/file_logger.c (+14/-10) plugin/audit_log/logger.h (+6/-1) |
||||
To merge this branch: | bzr merge lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Laurynas Biveinis (community) | Approve | ||
Review via email: mp+232843@code.launchpad.net |
Commit message
Description of the change
1. Fix ids of 3 files
2. Automerge fix for bug 1363370
http://
To post a comment you must log in.
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote : | # |
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote : | # |
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'mysql-test/r/audit_log_rotate.result' | |||
2 | --- mysql-test/r/audit_log_rotate.result 1970-01-01 00:00:00 +0000 | |||
3 | +++ mysql-test/r/audit_log_rotate.result 2014-09-26 09:26:38 +0000 | |||
4 | @@ -0,0 +1,1 @@ | |||
5 | 1 | success | ||
6 | 0 | 2 | ||
7 | === added file 'mysql-test/t/audit_log_rotate-master.opt' | |||
8 | --- mysql-test/t/audit_log_rotate-master.opt 1970-01-01 00:00:00 +0000 | |||
9 | +++ mysql-test/t/audit_log_rotate-master.opt 2014-09-26 09:26:38 +0000 | |||
10 | @@ -0,0 +1,8 @@ | |||
11 | 1 | $AUDIT_LOG_OPT | ||
12 | 2 | $AUDIT_LOG_LOAD | ||
13 | 3 | --audit_log_file=test_audit.log | ||
14 | 4 | --audit_log_format=JSON | ||
15 | 5 | --audit_log_strategy=ASYNCHRONOUS | ||
16 | 6 | --audit_log_rotate_on_size=4096 | ||
17 | 7 | --audit_log_buffer_size=5000 | ||
18 | 8 | --audit_log_rotations=10 | ||
19 | 0 | 9 | ||
20 | === added file 'mysql-test/t/audit_log_rotate.test' | |||
21 | --- mysql-test/t/audit_log_rotate.test 1970-01-01 00:00:00 +0000 | |||
22 | +++ mysql-test/t/audit_log_rotate.test 2014-09-26 09:26:38 +0000 | |||
23 | @@ -0,0 +1,29 @@ | |||
24 | 1 | --source include/not_embedded.inc | ||
25 | 2 | |||
26 | 3 | let $MYSQLD_DATADIR= `select @@datadir`; | ||
27 | 4 | let MYSQLD_DATADIR= $MYSQLD_DATADIR; | ||
28 | 5 | |||
29 | 6 | --disable_result_log | ||
30 | 7 | --disable_query_log | ||
31 | 8 | --source include/audit_log_events.inc | ||
32 | 9 | --source include/audit_log_events.inc | ||
33 | 10 | --source include/audit_log_events.inc | ||
34 | 11 | --source include/audit_log_events.inc | ||
35 | 12 | --enable_query_log | ||
36 | 13 | --enable_result_log | ||
37 | 14 | |||
38 | 15 | perl; | ||
39 | 16 | eval "use JSON qw(decode_json); 1" or exit 0; | ||
40 | 17 | my @files = glob ($ENV{'MYSQLD_DATADIR'} . "/test_audit.log.*"); | ||
41 | 18 | foreach (@files) { | ||
42 | 19 | open my $file, $_ or die "Could not open log: $!"; | ||
43 | 20 | while (my $line = <$file>) { | ||
44 | 21 | decode_json($line); | ||
45 | 22 | } | ||
46 | 23 | close $file; | ||
47 | 24 | } | ||
48 | 25 | die "Rotation doesn't wrok!" unless scalar(@files) > 1 | ||
49 | 26 | EOF | ||
50 | 27 | --remove_files_wildcard $MYSQLD_DATADIR test_audit.log* | ||
51 | 28 | |||
52 | 29 | --echo success | ||
53 | 0 | 30 | ||
54 | === added file 'plugin/audit_log/audit_file.c' | |||
55 | --- plugin/audit_log/audit_file.c 1970-01-01 00:00:00 +0000 | |||
56 | +++ plugin/audit_log/audit_file.c 2014-09-26 09:26:38 +0000 | |||
57 | @@ -0,0 +1,204 @@ | |||
58 | 1 | /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. | ||
59 | 2 | |||
60 | 3 | This program is free software; you can redistribute it and/or | ||
61 | 4 | modify it under the terms of the GNU General Public License | ||
62 | 5 | as published by the Free Software Foundation; version 2 of | ||
63 | 6 | the License. | ||
64 | 7 | |||
65 | 8 | This program is distributed in the hope that it will be useful, | ||
66 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
67 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
68 | 11 | GNU General Public License for more details. | ||
69 | 12 | |||
70 | 13 | You should have received a copy of the GNU General Public License | ||
71 | 14 | along with this program; if not, write to the Free Software | ||
72 | 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
73 | 16 | |||
74 | 17 | #include "audit_handler.h" | ||
75 | 18 | #include "buffer.h" | ||
76 | 19 | |||
77 | 20 | typedef struct audit_handler_file_data_struct audit_handler_file_data_t; | ||
78 | 21 | |||
79 | 22 | struct audit_handler_file_data_struct | ||
80 | 23 | { | ||
81 | 24 | size_t struct_size; | ||
82 | 25 | LOGGER_HANDLE *logger; | ||
83 | 26 | logger_prolog_func_t header; | ||
84 | 27 | logger_epilog_func_t footer; | ||
85 | 28 | my_bool sync_on_write; | ||
86 | 29 | my_bool use_buffer; | ||
87 | 30 | audit_log_buffer_t *buffer; | ||
88 | 31 | }; | ||
89 | 32 | |||
90 | 33 | static | ||
91 | 34 | int audit_handler_file_write(audit_handler_t *handler, | ||
92 | 35 | const char *buf, size_t len); | ||
93 | 36 | static | ||
94 | 37 | int audit_handler_file_flush(audit_handler_t *handler); | ||
95 | 38 | static | ||
96 | 39 | int audit_handler_file_close(audit_handler_t *handler); | ||
97 | 40 | static | ||
98 | 41 | int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger, | ||
99 | 42 | const char *buf, size_t len, | ||
100 | 43 | log_record_state_t state); | ||
101 | 44 | static | ||
102 | 45 | int audit_handler_file_write_buf(audit_log_buffer_t *buffer, | ||
103 | 46 | const char *buf, size_t len); | ||
104 | 47 | static | ||
105 | 48 | void audit_handler_file_set_option(audit_handler_t *handler, | ||
106 | 49 | audit_handler_option_t opt, void *val); | ||
107 | 50 | |||
108 | 51 | static | ||
109 | 52 | int write_callback(void *data, const char *buf, size_t len, | ||
110 | 53 | log_record_state_t state) | ||
111 | 54 | { | ||
112 | 55 | audit_handler_t *handler= (audit_handler_t *) data; | ||
113 | 56 | audit_handler_file_data_t *hdata= (audit_handler_file_data_t*) handler->data; | ||
114 | 57 | |||
115 | 58 | DBUG_ASSERT(hdata->struct_size == sizeof(audit_handler_file_data_t)); | ||
116 | 59 | |||
117 | 60 | return audit_handler_file_write_nobuf(hdata->logger, buf, len, state); | ||
118 | 61 | } | ||
119 | 62 | |||
120 | 63 | |||
121 | 64 | audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts) | ||
122 | 65 | { | ||
123 | 66 | audit_handler_t *handler= (audit_handler_t*) | ||
124 | 67 | calloc(sizeof(audit_handler_t) + sizeof(audit_handler_file_data_t), 1); | ||
125 | 68 | if (handler != NULL) | ||
126 | 69 | { | ||
127 | 70 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) (handler + 1); | ||
128 | 71 | data->struct_size= sizeof(audit_handler_file_data_t); | ||
129 | 72 | data->footer= opts->footer; | ||
130 | 73 | data->header= opts->header; | ||
131 | 74 | data->sync_on_write= opts->sync_on_write; | ||
132 | 75 | data->use_buffer= opts->use_buffer; | ||
133 | 76 | if (data->use_buffer) | ||
134 | 77 | { | ||
135 | 78 | data->buffer= audit_log_buffer_init(opts->buffer_size, | ||
136 | 79 | opts->can_drop_data, | ||
137 | 80 | write_callback, handler); | ||
138 | 81 | if (data->buffer == NULL) | ||
139 | 82 | goto error; | ||
140 | 83 | } | ||
141 | 84 | data->logger= logger_open(opts->name, opts->rotate_on_size, | ||
142 | 85 | opts->rotate_on_size ? opts->rotations : 0, | ||
143 | 86 | !opts->use_buffer, opts->header); | ||
144 | 87 | if (data->logger == NULL) | ||
145 | 88 | { | ||
146 | 89 | goto error; | ||
147 | 90 | } | ||
148 | 91 | handler->data= data; | ||
149 | 92 | handler->write= audit_handler_file_write; | ||
150 | 93 | handler->flush= audit_handler_file_flush; | ||
151 | 94 | handler->close= audit_handler_file_close; | ||
152 | 95 | handler->set_option= audit_handler_file_set_option; | ||
153 | 96 | goto success; | ||
154 | 97 | error: | ||
155 | 98 | if (data->use_buffer) | ||
156 | 99 | { | ||
157 | 100 | free(data->buffer); | ||
158 | 101 | } | ||
159 | 102 | free(handler); | ||
160 | 103 | handler= NULL; | ||
161 | 104 | } | ||
162 | 105 | success: | ||
163 | 106 | return handler; | ||
164 | 107 | } | ||
165 | 108 | |||
166 | 109 | static | ||
167 | 110 | int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger, | ||
168 | 111 | const char *buf, size_t len, | ||
169 | 112 | log_record_state_t state) | ||
170 | 113 | { | ||
171 | 114 | return logger_write(logger, buf, len, state); | ||
172 | 115 | } | ||
173 | 116 | |||
174 | 117 | static | ||
175 | 118 | int audit_handler_file_write_buf(audit_log_buffer_t *buffer, | ||
176 | 119 | const char *buf, size_t len) | ||
177 | 120 | { | ||
178 | 121 | return audit_log_buffer_write(buffer, buf, len); | ||
179 | 122 | } | ||
180 | 123 | |||
181 | 124 | static | ||
182 | 125 | int audit_handler_file_write(audit_handler_t *handler, | ||
183 | 126 | const char *buf, size_t len) | ||
184 | 127 | { | ||
185 | 128 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
186 | 129 | int res; | ||
187 | 130 | |||
188 | 131 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t)); | ||
189 | 132 | |||
190 | 133 | if (data->use_buffer) | ||
191 | 134 | { | ||
192 | 135 | DBUG_ASSERT(data->buffer); | ||
193 | 136 | res= audit_handler_file_write_buf(data->buffer, buf, len); | ||
194 | 137 | } | ||
195 | 138 | else | ||
196 | 139 | { | ||
197 | 140 | DBUG_ASSERT(data->logger); | ||
198 | 141 | res= audit_handler_file_write_nobuf(data->logger, buf, len, | ||
199 | 142 | LOG_RECORD_COMPLETE); | ||
200 | 143 | |||
201 | 144 | if (data->sync_on_write) | ||
202 | 145 | { | ||
203 | 146 | logger_sync(data->logger); | ||
204 | 147 | } | ||
205 | 148 | } | ||
206 | 149 | |||
207 | 150 | return res; | ||
208 | 151 | } | ||
209 | 152 | |||
210 | 153 | static | ||
211 | 154 | int audit_handler_file_flush(audit_handler_t *handler) | ||
212 | 155 | { | ||
213 | 156 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
214 | 157 | LOGGER_HANDLE* logger; | ||
215 | 158 | |||
216 | 159 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t)); | ||
217 | 160 | |||
218 | 161 | logger= data->logger; | ||
219 | 162 | |||
220 | 163 | return logger_reopen(logger, data->header, data->footer); | ||
221 | 164 | } | ||
222 | 165 | |||
223 | 166 | static | ||
224 | 167 | int audit_handler_file_close(audit_handler_t *handler) | ||
225 | 168 | { | ||
226 | 169 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
227 | 170 | int res; | ||
228 | 171 | LOGGER_HANDLE* logger; | ||
229 | 172 | |||
230 | 173 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t)); | ||
231 | 174 | |||
232 | 175 | logger= data->logger; | ||
233 | 176 | |||
234 | 177 | if (data->use_buffer) | ||
235 | 178 | { | ||
236 | 179 | audit_log_buffer_shutdown(data->buffer); | ||
237 | 180 | } | ||
238 | 181 | |||
239 | 182 | res= logger_close(logger, data->footer); | ||
240 | 183 | |||
241 | 184 | free(handler); | ||
242 | 185 | |||
243 | 186 | return res; | ||
244 | 187 | } | ||
245 | 188 | |||
246 | 189 | static | ||
247 | 190 | void audit_handler_file_set_option(audit_handler_t *handler, | ||
248 | 191 | audit_handler_option_t opt, void *val) | ||
249 | 192 | { | ||
250 | 193 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
251 | 194 | |||
252 | 195 | switch (opt) | ||
253 | 196 | { | ||
254 | 197 | case OPT_ROTATIONS: | ||
255 | 198 | logger_set_size_limit(data->logger, *(ulonglong*)(val)); | ||
256 | 199 | break; | ||
257 | 200 | case OPT_ROTATE_ON_SIZE: | ||
258 | 201 | logger_set_rotations(data->logger, *(ulonglong*)(val)); | ||
259 | 202 | break; | ||
260 | 203 | } | ||
261 | 204 | } | ||
262 | 0 | 205 | ||
263 | === removed file 'plugin/audit_log/audit_file.c' | |||
264 | --- plugin/audit_log/audit_file.c 2014-07-30 16:48:53 +0000 | |||
265 | +++ plugin/audit_log/audit_file.c 1970-01-01 00:00:00 +0000 | |||
266 | @@ -1,200 +0,0 @@ | |||
267 | 1 | /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. | ||
268 | 2 | |||
269 | 3 | This program is free software; you can redistribute it and/or | ||
270 | 4 | modify it under the terms of the GNU General Public License | ||
271 | 5 | as published by the Free Software Foundation; version 2 of | ||
272 | 6 | the License. | ||
273 | 7 | |||
274 | 8 | This program is distributed in the hope that it will be useful, | ||
275 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
276 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
277 | 11 | GNU General Public License for more details. | ||
278 | 12 | |||
279 | 13 | You should have received a copy of the GNU General Public License | ||
280 | 14 | along with this program; if not, write to the Free Software | ||
281 | 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
282 | 16 | |||
283 | 17 | #include "audit_handler.h" | ||
284 | 18 | #include "buffer.h" | ||
285 | 19 | |||
286 | 20 | typedef struct audit_handler_file_data_struct audit_handler_file_data_t; | ||
287 | 21 | |||
288 | 22 | struct audit_handler_file_data_struct | ||
289 | 23 | { | ||
290 | 24 | size_t struct_size; | ||
291 | 25 | LOGGER_HANDLE *logger; | ||
292 | 26 | logger_prolog_func_t header; | ||
293 | 27 | logger_epilog_func_t footer; | ||
294 | 28 | my_bool sync_on_write; | ||
295 | 29 | my_bool use_buffer; | ||
296 | 30 | audit_log_buffer_t *buffer; | ||
297 | 31 | }; | ||
298 | 32 | |||
299 | 33 | static | ||
300 | 34 | int audit_handler_file_write(audit_handler_t *handler, | ||
301 | 35 | const char *buf, size_t len); | ||
302 | 36 | static | ||
303 | 37 | int audit_handler_file_flush(audit_handler_t *handler); | ||
304 | 38 | static | ||
305 | 39 | int audit_handler_file_close(audit_handler_t *handler); | ||
306 | 40 | static | ||
307 | 41 | int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger, | ||
308 | 42 | const char *buf, size_t len); | ||
309 | 43 | static | ||
310 | 44 | int audit_handler_file_write_buf(audit_log_buffer_t *buffer, | ||
311 | 45 | const char *buf, size_t len); | ||
312 | 46 | static | ||
313 | 47 | void audit_handler_file_set_option(audit_handler_t *handler, | ||
314 | 48 | audit_handler_option_t opt, void *val); | ||
315 | 49 | |||
316 | 50 | static | ||
317 | 51 | int write_callback(void *data, const char *buf, size_t len) | ||
318 | 52 | { | ||
319 | 53 | audit_handler_t *handler= (audit_handler_t *) data; | ||
320 | 54 | audit_handler_file_data_t *hdata= (audit_handler_file_data_t*) handler->data; | ||
321 | 55 | |||
322 | 56 | DBUG_ASSERT(hdata->struct_size == sizeof(audit_handler_file_data_t)); | ||
323 | 57 | |||
324 | 58 | return audit_handler_file_write_nobuf(hdata->logger, buf, len); | ||
325 | 59 | } | ||
326 | 60 | |||
327 | 61 | |||
328 | 62 | audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts) | ||
329 | 63 | { | ||
330 | 64 | audit_handler_t *handler= (audit_handler_t*) | ||
331 | 65 | calloc(sizeof(audit_handler_t) + sizeof(audit_handler_file_data_t), 1); | ||
332 | 66 | if (handler != NULL) | ||
333 | 67 | { | ||
334 | 68 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) (handler + 1); | ||
335 | 69 | data->struct_size= sizeof(audit_handler_file_data_t); | ||
336 | 70 | data->footer= opts->footer; | ||
337 | 71 | data->header= opts->header; | ||
338 | 72 | data->sync_on_write= opts->sync_on_write; | ||
339 | 73 | data->use_buffer= opts->use_buffer; | ||
340 | 74 | if (data->use_buffer) | ||
341 | 75 | { | ||
342 | 76 | data->buffer= audit_log_buffer_init(opts->buffer_size, | ||
343 | 77 | opts->can_drop_data, | ||
344 | 78 | write_callback, handler); | ||
345 | 79 | if (data->buffer == NULL) | ||
346 | 80 | goto error; | ||
347 | 81 | } | ||
348 | 82 | data->logger= logger_open(opts->name, opts->rotate_on_size, | ||
349 | 83 | opts->rotate_on_size ? opts->rotations : 0, | ||
350 | 84 | !opts->use_buffer, opts->header); | ||
351 | 85 | if (data->logger == NULL) | ||
352 | 86 | { | ||
353 | 87 | goto error; | ||
354 | 88 | } | ||
355 | 89 | handler->data= data; | ||
356 | 90 | handler->write= audit_handler_file_write; | ||
357 | 91 | handler->flush= audit_handler_file_flush; | ||
358 | 92 | handler->close= audit_handler_file_close; | ||
359 | 93 | handler->set_option= audit_handler_file_set_option; | ||
360 | 94 | goto success; | ||
361 | 95 | error: | ||
362 | 96 | if (data->use_buffer) | ||
363 | 97 | { | ||
364 | 98 | free(data->buffer); | ||
365 | 99 | } | ||
366 | 100 | free(handler); | ||
367 | 101 | handler= NULL; | ||
368 | 102 | } | ||
369 | 103 | success: | ||
370 | 104 | return handler; | ||
371 | 105 | } | ||
372 | 106 | |||
373 | 107 | static | ||
374 | 108 | int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger, | ||
375 | 109 | const char *buf, size_t len) | ||
376 | 110 | { | ||
377 | 111 | return logger_write(logger, buf, len); | ||
378 | 112 | } | ||
379 | 113 | |||
380 | 114 | static | ||
381 | 115 | int audit_handler_file_write_buf(audit_log_buffer_t *buffer, | ||
382 | 116 | const char *buf, size_t len) | ||
383 | 117 | { | ||
384 | 118 | return audit_log_buffer_write(buffer, buf, len); | ||
385 | 119 | } | ||
386 | 120 | |||
387 | 121 | static | ||
388 | 122 | int audit_handler_file_write(audit_handler_t *handler, | ||
389 | 123 | const char *buf, size_t len) | ||
390 | 124 | { | ||
391 | 125 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
392 | 126 | int res; | ||
393 | 127 | |||
394 | 128 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t)); | ||
395 | 129 | |||
396 | 130 | if (data->use_buffer) | ||
397 | 131 | { | ||
398 | 132 | DBUG_ASSERT(data->buffer); | ||
399 | 133 | res= audit_handler_file_write_buf(data->buffer, buf, len); | ||
400 | 134 | } | ||
401 | 135 | else | ||
402 | 136 | { | ||
403 | 137 | DBUG_ASSERT(data->logger); | ||
404 | 138 | res= audit_handler_file_write_nobuf(data->logger, buf, len); | ||
405 | 139 | |||
406 | 140 | if (data->sync_on_write) | ||
407 | 141 | { | ||
408 | 142 | logger_sync(data->logger); | ||
409 | 143 | } | ||
410 | 144 | } | ||
411 | 145 | |||
412 | 146 | return res; | ||
413 | 147 | } | ||
414 | 148 | |||
415 | 149 | static | ||
416 | 150 | int audit_handler_file_flush(audit_handler_t *handler) | ||
417 | 151 | { | ||
418 | 152 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
419 | 153 | LOGGER_HANDLE* logger; | ||
420 | 154 | |||
421 | 155 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t)); | ||
422 | 156 | |||
423 | 157 | logger= data->logger; | ||
424 | 158 | |||
425 | 159 | return logger_reopen(logger, data->header, data->footer); | ||
426 | 160 | } | ||
427 | 161 | |||
428 | 162 | static | ||
429 | 163 | int audit_handler_file_close(audit_handler_t *handler) | ||
430 | 164 | { | ||
431 | 165 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
432 | 166 | int res; | ||
433 | 167 | LOGGER_HANDLE* logger; | ||
434 | 168 | |||
435 | 169 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t)); | ||
436 | 170 | |||
437 | 171 | logger= data->logger; | ||
438 | 172 | |||
439 | 173 | if (data->use_buffer) | ||
440 | 174 | { | ||
441 | 175 | audit_log_buffer_shutdown(data->buffer); | ||
442 | 176 | } | ||
443 | 177 | |||
444 | 178 | res= logger_close(logger, data->footer); | ||
445 | 179 | |||
446 | 180 | free(handler); | ||
447 | 181 | |||
448 | 182 | return res; | ||
449 | 183 | } | ||
450 | 184 | |||
451 | 185 | static | ||
452 | 186 | void audit_handler_file_set_option(audit_handler_t *handler, | ||
453 | 187 | audit_handler_option_t opt, void *val) | ||
454 | 188 | { | ||
455 | 189 | audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data; | ||
456 | 190 | |||
457 | 191 | switch (opt) | ||
458 | 192 | { | ||
459 | 193 | case OPT_ROTATIONS: | ||
460 | 194 | logger_set_size_limit(data->logger, *(ulonglong*)(val)); | ||
461 | 195 | break; | ||
462 | 196 | case OPT_ROTATE_ON_SIZE: | ||
463 | 197 | logger_set_rotations(data->logger, *(ulonglong*)(val)); | ||
464 | 198 | break; | ||
465 | 199 | } | ||
466 | 200 | } | ||
467 | 201 | 0 | ||
468 | === added file 'plugin/audit_log/audit_handler.h' | |||
469 | --- plugin/audit_log/audit_handler.h 1970-01-01 00:00:00 +0000 | |||
470 | +++ plugin/audit_log/audit_handler.h 2014-09-26 09:26:38 +0000 | |||
471 | @@ -0,0 +1,116 @@ | |||
472 | 1 | /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. | ||
473 | 2 | |||
474 | 3 | This program is free software; you can redistribute it and/or | ||
475 | 4 | modify it under the terms of the GNU General Public License | ||
476 | 5 | as published by the Free Software Foundation; version 2 of | ||
477 | 6 | the License. | ||
478 | 7 | |||
479 | 8 | This program is distributed in the hope that it will be useful, | ||
480 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
481 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
482 | 11 | GNU General Public License for more details. | ||
483 | 12 | |||
484 | 13 | You should have received a copy of the GNU General Public License | ||
485 | 14 | along with this program; if not, write to the Free Software | ||
486 | 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
487 | 16 | |||
488 | 17 | |||
489 | 18 | #ifndef AUDIT_HANDLER_INCLUDED | ||
490 | 19 | #define AUDIT_HANDLER_INCLUDED | ||
491 | 20 | |||
492 | 21 | #include <my_global.h> | ||
493 | 22 | |||
494 | 23 | #include "logger.h" | ||
495 | 24 | |||
496 | 25 | #ifdef __cplusplus | ||
497 | 26 | extern "C" { | ||
498 | 27 | #endif | ||
499 | 28 | |||
500 | 29 | typedef struct audit_handler_struct audit_handler_t; | ||
501 | 30 | typedef struct audit_handler_file_config_struct audit_handler_file_config_t; | ||
502 | 31 | typedef struct audit_handler_syslog_config_struct audit_handler_syslog_config_t; | ||
503 | 32 | typedef struct audit_handler_buffered_struct audit_handler_buffered_t; | ||
504 | 33 | typedef void * audit_handler_data_t; | ||
505 | 34 | |||
506 | 35 | |||
507 | 36 | typedef enum { OPT_ROTATE_ON_SIZE, OPT_ROTATIONS } audit_handler_option_t; | ||
508 | 37 | |||
509 | 38 | struct audit_handler_struct | ||
510 | 39 | { | ||
511 | 40 | int (*write)(audit_handler_t *, const char *, size_t); | ||
512 | 41 | int (*flush)(audit_handler_t *); | ||
513 | 42 | int (*close)(audit_handler_t *); | ||
514 | 43 | void (*set_option)(audit_handler_t *, audit_handler_option_t, void *); | ||
515 | 44 | audit_handler_data_t data; | ||
516 | 45 | }; | ||
517 | 46 | |||
518 | 47 | struct audit_handler_file_config_struct | ||
519 | 48 | { | ||
520 | 49 | const char *name; | ||
521 | 50 | size_t rotate_on_size; | ||
522 | 51 | size_t rotations; | ||
523 | 52 | my_bool sync_on_write; | ||
524 | 53 | my_bool use_buffer; | ||
525 | 54 | size_t buffer_size; | ||
526 | 55 | my_bool can_drop_data; | ||
527 | 56 | logger_prolog_func_t header; | ||
528 | 57 | logger_epilog_func_t footer; | ||
529 | 58 | }; | ||
530 | 59 | |||
531 | 60 | struct audit_handler_syslog_config_struct | ||
532 | 61 | { | ||
533 | 62 | const char *ident; | ||
534 | 63 | int facility; | ||
535 | 64 | int priority; | ||
536 | 65 | logger_prolog_func_t header; | ||
537 | 66 | logger_epilog_func_t footer; | ||
538 | 67 | }; | ||
539 | 68 | |||
540 | 69 | static inline | ||
541 | 70 | int audit_handler_write(audit_handler_t *handler, const char *buf, size_t len) | ||
542 | 71 | { | ||
543 | 72 | if (handler->write != NULL) | ||
544 | 73 | { | ||
545 | 74 | return handler->write(handler, buf, len); | ||
546 | 75 | } | ||
547 | 76 | return len; | ||
548 | 77 | } | ||
549 | 78 | |||
550 | 79 | static inline | ||
551 | 80 | int audit_handler_flush(audit_handler_t *handler) | ||
552 | 81 | { | ||
553 | 82 | if (handler->flush != NULL) | ||
554 | 83 | { | ||
555 | 84 | return handler->flush(handler); | ||
556 | 85 | } | ||
557 | 86 | return 0; | ||
558 | 87 | } | ||
559 | 88 | |||
560 | 89 | static inline | ||
561 | 90 | int audit_handler_close(audit_handler_t *handler) | ||
562 | 91 | { | ||
563 | 92 | if (handler->close != NULL) | ||
564 | 93 | { | ||
565 | 94 | return handler->close(handler); | ||
566 | 95 | } | ||
567 | 96 | return 0; | ||
568 | 97 | } | ||
569 | 98 | |||
570 | 99 | static inline | ||
571 | 100 | void audit_handler_set_option(audit_handler_t *handler, | ||
572 | 101 | audit_handler_option_t opt, void *val) | ||
573 | 102 | { | ||
574 | 103 | if (handler->set_option != NULL) | ||
575 | 104 | { | ||
576 | 105 | handler->set_option(handler, opt, val); | ||
577 | 106 | } | ||
578 | 107 | } | ||
579 | 108 | |||
580 | 109 | audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts); | ||
581 | 110 | audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts); | ||
582 | 111 | |||
583 | 112 | #ifdef __cplusplus | ||
584 | 113 | } | ||
585 | 114 | #endif | ||
586 | 115 | |||
587 | 116 | #endif | ||
588 | 0 | 117 | ||
589 | === removed file 'plugin/audit_log/audit_handler.h' | |||
590 | --- plugin/audit_log/audit_handler.h 2014-07-30 16:48:53 +0000 | |||
591 | +++ plugin/audit_log/audit_handler.h 1970-01-01 00:00:00 +0000 | |||
592 | @@ -1,116 +0,0 @@ | |||
593 | 1 | /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. | ||
594 | 2 | |||
595 | 3 | This program is free software; you can redistribute it and/or | ||
596 | 4 | modify it under the terms of the GNU General Public License | ||
597 | 5 | as published by the Free Software Foundation; version 2 of | ||
598 | 6 | the License. | ||
599 | 7 | |||
600 | 8 | This program is distributed in the hope that it will be useful, | ||
601 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
602 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
603 | 11 | GNU General Public License for more details. | ||
604 | 12 | |||
605 | 13 | You should have received a copy of the GNU General Public License | ||
606 | 14 | along with this program; if not, write to the Free Software | ||
607 | 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
608 | 16 | |||
609 | 17 | |||
610 | 18 | #ifndef AUDIT_HANDLER_INCLUDED | ||
611 | 19 | #define AUDIT_HANDLER_INCLUDED | ||
612 | 20 | |||
613 | 21 | #include <my_global.h> | ||
614 | 22 | |||
615 | 23 | #include "logger.h" | ||
616 | 24 | |||
617 | 25 | #ifdef __cplusplus | ||
618 | 26 | extern "C" { | ||
619 | 27 | #endif | ||
620 | 28 | |||
621 | 29 | typedef struct audit_handler_struct audit_handler_t; | ||
622 | 30 | typedef struct audit_handler_file_config_struct audit_handler_file_config_t; | ||
623 | 31 | typedef struct audit_handler_syslog_config_struct audit_handler_syslog_config_t; | ||
624 | 32 | typedef struct audit_handler_buffered_struct audit_handler_buffered_t; | ||
625 | 33 | typedef void * audit_handler_data_t; | ||
626 | 34 | |||
627 | 35 | |||
628 | 36 | typedef enum { OPT_ROTATE_ON_SIZE, OPT_ROTATIONS } audit_handler_option_t; | ||
629 | 37 | |||
630 | 38 | struct audit_handler_struct | ||
631 | 39 | { | ||
632 | 40 | int (*write)(audit_handler_t *, const char *, size_t); | ||
633 | 41 | int (*flush)(audit_handler_t *); | ||
634 | 42 | int (*close)(audit_handler_t *); | ||
635 | 43 | void (*set_option)(audit_handler_t *, audit_handler_option_t, void *); | ||
636 | 44 | audit_handler_data_t data; | ||
637 | 45 | }; | ||
638 | 46 | |||
639 | 47 | struct audit_handler_file_config_struct | ||
640 | 48 | { | ||
641 | 49 | const char *name; | ||
642 | 50 | size_t rotate_on_size; | ||
643 | 51 | size_t rotations; | ||
644 | 52 | my_bool sync_on_write; | ||
645 | 53 | my_bool use_buffer; | ||
646 | 54 | size_t buffer_size; | ||
647 | 55 | my_bool can_drop_data; | ||
648 | 56 | logger_prolog_func_t header; | ||
649 | 57 | logger_epilog_func_t footer; | ||
650 | 58 | }; | ||
651 | 59 | |||
652 | 60 | struct audit_handler_syslog_config_struct | ||
653 | 61 | { | ||
654 | 62 | const char *ident; | ||
655 | 63 | int facility; | ||
656 | 64 | int priority; | ||
657 | 65 | logger_prolog_func_t header; | ||
658 | 66 | logger_epilog_func_t footer; | ||
659 | 67 | }; | ||
660 | 68 | |||
661 | 69 | static inline | ||
662 | 70 | int audit_handler_write(audit_handler_t *handler, const char *buf, size_t len) | ||
663 | 71 | { | ||
664 | 72 | if (handler->write != NULL) | ||
665 | 73 | { | ||
666 | 74 | return handler->write(handler, buf, len); | ||
667 | 75 | } | ||
668 | 76 | return len; | ||
669 | 77 | } | ||
670 | 78 | |||
671 | 79 | static inline | ||
672 | 80 | int audit_handler_flush(audit_handler_t *handler) | ||
673 | 81 | { | ||
674 | 82 | if (handler->flush != NULL) | ||
675 | 83 | { | ||
676 | 84 | return handler->flush(handler); | ||
677 | 85 | } | ||
678 | 86 | return 0; | ||
679 | 87 | } | ||
680 | 88 | |||
681 | 89 | static inline | ||
682 | 90 | int audit_handler_close(audit_handler_t *handler) | ||
683 | 91 | { | ||
684 | 92 | if (handler->close != NULL) | ||
685 | 93 | { | ||
686 | 94 | return handler->close(handler); | ||
687 | 95 | } | ||
688 | 96 | return 0; | ||
689 | 97 | } | ||
690 | 98 | |||
691 | 99 | static inline | ||
692 | 100 | void audit_handler_set_option(audit_handler_t *handler, | ||
693 | 101 | audit_handler_option_t opt, void *val) | ||
694 | 102 | { | ||
695 | 103 | if (handler->set_option != NULL) | ||
696 | 104 | { | ||
697 | 105 | handler->set_option(handler, opt, val); | ||
698 | 106 | } | ||
699 | 107 | } | ||
700 | 108 | |||
701 | 109 | audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts); | ||
702 | 110 | audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts); | ||
703 | 111 | |||
704 | 112 | #ifdef __cplusplus | ||
705 | 113 | } | ||
706 | 114 | #endif | ||
707 | 115 | |||
708 | 116 | #endif | ||
709 | 117 | 0 | ||
710 | === added file 'plugin/audit_log/audit_syslog.c' | |||
711 | --- plugin/audit_log/audit_syslog.c 1970-01-01 00:00:00 +0000 | |||
712 | +++ plugin/audit_log/audit_syslog.c 2014-09-26 09:26:38 +0000 | |||
713 | @@ -0,0 +1,91 @@ | |||
714 | 1 | /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. | ||
715 | 2 | |||
716 | 3 | This program is free software; you can redistribute it and/or | ||
717 | 4 | modify it under the terms of the GNU General Public License | ||
718 | 5 | as published by the Free Software Foundation; version 2 of | ||
719 | 6 | the License. | ||
720 | 7 | |||
721 | 8 | This program is distributed in the hope that it will be useful, | ||
722 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
723 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
724 | 11 | GNU General Public License for more details. | ||
725 | 12 | |||
726 | 13 | You should have received a copy of the GNU General Public License | ||
727 | 14 | along with this program; if not, write to the Free Software | ||
728 | 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
729 | 16 | |||
730 | 17 | #include <syslog.h> | ||
731 | 18 | #include <string.h> | ||
732 | 19 | #include "audit_handler.h" | ||
733 | 20 | |||
734 | 21 | typedef struct audit_handler_syslog_data_struct audit_handler_syslog_data_t; | ||
735 | 22 | |||
736 | 23 | struct audit_handler_syslog_data_struct | ||
737 | 24 | { | ||
738 | 25 | size_t struct_size; | ||
739 | 26 | int priority; | ||
740 | 27 | logger_prolog_func_t header; | ||
741 | 28 | logger_epilog_func_t footer; | ||
742 | 29 | }; | ||
743 | 30 | |||
744 | 31 | int audit_handler_syslog_write(audit_handler_t *handler, | ||
745 | 32 | const char *buf, size_t len); | ||
746 | 33 | int audit_handler_syslog_flush(audit_handler_t *handler); | ||
747 | 34 | int audit_handler_syslog_close(audit_handler_t *handler); | ||
748 | 35 | |||
749 | 36 | |||
750 | 37 | audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts) | ||
751 | 38 | { | ||
752 | 39 | audit_handler_t *handler= (audit_handler_t*) | ||
753 | 40 | calloc(sizeof(audit_handler_t) + sizeof(audit_handler_syslog_data_t), 1); | ||
754 | 41 | if (handler != NULL) | ||
755 | 42 | { | ||
756 | 43 | audit_handler_syslog_data_t *data= | ||
757 | 44 | (audit_handler_syslog_data_t*) (handler + 1); | ||
758 | 45 | MY_STAT stat_arg; | ||
759 | 46 | |||
760 | 47 | data->struct_size= sizeof(audit_handler_syslog_data_t); | ||
761 | 48 | data->priority= opts->priority; | ||
762 | 49 | data->header= opts->header; | ||
763 | 50 | data->footer= opts->footer; | ||
764 | 51 | openlog(opts->ident, 0, opts->facility); | ||
765 | 52 | memset(&stat_arg, 0, sizeof(stat_arg)); | ||
766 | 53 | opts->header(&stat_arg, NULL, 0); | ||
767 | 54 | handler->data= data; | ||
768 | 55 | handler->write= audit_handler_syslog_write; | ||
769 | 56 | handler->flush= audit_handler_syslog_flush; | ||
770 | 57 | handler->close= audit_handler_syslog_close; | ||
771 | 58 | } | ||
772 | 59 | return handler; | ||
773 | 60 | } | ||
774 | 61 | |||
775 | 62 | int audit_handler_syslog_write(audit_handler_t *handler, | ||
776 | 63 | const char *buf, size_t len) | ||
777 | 64 | { | ||
778 | 65 | audit_handler_syslog_data_t *data= | ||
779 | 66 | (audit_handler_syslog_data_t*) handler->data; | ||
780 | 67 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_syslog_data_t)); | ||
781 | 68 | syslog(data->priority, "%s", buf); | ||
782 | 69 | return len; | ||
783 | 70 | } | ||
784 | 71 | |||
785 | 72 | int audit_handler_syslog_flush(audit_handler_t *handler) | ||
786 | 73 | { | ||
787 | 74 | audit_handler_syslog_data_t *data= | ||
788 | 75 | (audit_handler_syslog_data_t*) handler->data; | ||
789 | 76 | MY_STAT stat_arg; | ||
790 | 77 | memset(&stat_arg, 0, sizeof(stat_arg)); | ||
791 | 78 | data->header(&stat_arg, NULL, 0); | ||
792 | 79 | data->footer(NULL, 0); | ||
793 | 80 | return 0; | ||
794 | 81 | } | ||
795 | 82 | |||
796 | 83 | int audit_handler_syslog_close(audit_handler_t *handler) | ||
797 | 84 | { | ||
798 | 85 | audit_handler_syslog_data_t *data= | ||
799 | 86 | (audit_handler_syslog_data_t*) handler->data; | ||
800 | 87 | data->footer(NULL, 0); | ||
801 | 88 | closelog(); | ||
802 | 89 | free(handler); | ||
803 | 90 | return 0; | ||
804 | 91 | } | ||
805 | 0 | 92 | ||
806 | === removed file 'plugin/audit_log/audit_syslog.c' | |||
807 | --- plugin/audit_log/audit_syslog.c 2014-07-30 16:48:53 +0000 | |||
808 | +++ plugin/audit_log/audit_syslog.c 1970-01-01 00:00:00 +0000 | |||
809 | @@ -1,91 +0,0 @@ | |||
810 | 1 | /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. | ||
811 | 2 | |||
812 | 3 | This program is free software; you can redistribute it and/or | ||
813 | 4 | modify it under the terms of the GNU General Public License | ||
814 | 5 | as published by the Free Software Foundation; version 2 of | ||
815 | 6 | the License. | ||
816 | 7 | |||
817 | 8 | This program is distributed in the hope that it will be useful, | ||
818 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
819 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
820 | 11 | GNU General Public License for more details. | ||
821 | 12 | |||
822 | 13 | You should have received a copy of the GNU General Public License | ||
823 | 14 | along with this program; if not, write to the Free Software | ||
824 | 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
825 | 16 | |||
826 | 17 | #include <syslog.h> | ||
827 | 18 | #include <string.h> | ||
828 | 19 | #include "audit_handler.h" | ||
829 | 20 | |||
830 | 21 | typedef struct audit_handler_syslog_data_struct audit_handler_syslog_data_t; | ||
831 | 22 | |||
832 | 23 | struct audit_handler_syslog_data_struct | ||
833 | 24 | { | ||
834 | 25 | size_t struct_size; | ||
835 | 26 | int priority; | ||
836 | 27 | logger_prolog_func_t header; | ||
837 | 28 | logger_epilog_func_t footer; | ||
838 | 29 | }; | ||
839 | 30 | |||
840 | 31 | int audit_handler_syslog_write(audit_handler_t *handler, | ||
841 | 32 | const char *buf, size_t len); | ||
842 | 33 | int audit_handler_syslog_flush(audit_handler_t *handler); | ||
843 | 34 | int audit_handler_syslog_close(audit_handler_t *handler); | ||
844 | 35 | |||
845 | 36 | |||
846 | 37 | audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts) | ||
847 | 38 | { | ||
848 | 39 | audit_handler_t *handler= (audit_handler_t*) | ||
849 | 40 | calloc(sizeof(audit_handler_t) + sizeof(audit_handler_syslog_data_t), 1); | ||
850 | 41 | if (handler != NULL) | ||
851 | 42 | { | ||
852 | 43 | audit_handler_syslog_data_t *data= | ||
853 | 44 | (audit_handler_syslog_data_t*) (handler + 1); | ||
854 | 45 | MY_STAT stat_arg; | ||
855 | 46 | |||
856 | 47 | data->struct_size= sizeof(audit_handler_syslog_data_t); | ||
857 | 48 | data->priority= opts->priority; | ||
858 | 49 | data->header= opts->header; | ||
859 | 50 | data->footer= opts->footer; | ||
860 | 51 | openlog(opts->ident, 0, opts->facility); | ||
861 | 52 | memset(&stat_arg, 0, sizeof(stat_arg)); | ||
862 | 53 | opts->header(&stat_arg, NULL, 0); | ||
863 | 54 | handler->data= data; | ||
864 | 55 | handler->write= audit_handler_syslog_write; | ||
865 | 56 | handler->flush= audit_handler_syslog_flush; | ||
866 | 57 | handler->close= audit_handler_syslog_close; | ||
867 | 58 | } | ||
868 | 59 | return handler; | ||
869 | 60 | } | ||
870 | 61 | |||
871 | 62 | int audit_handler_syslog_write(audit_handler_t *handler, | ||
872 | 63 | const char *buf, size_t len) | ||
873 | 64 | { | ||
874 | 65 | audit_handler_syslog_data_t *data= | ||
875 | 66 | (audit_handler_syslog_data_t*) handler->data; | ||
876 | 67 | DBUG_ASSERT(data->struct_size == sizeof(audit_handler_syslog_data_t)); | ||
877 | 68 | syslog(data->priority, "%s", buf); | ||
878 | 69 | return len; | ||
879 | 70 | } | ||
880 | 71 | |||
881 | 72 | int audit_handler_syslog_flush(audit_handler_t *handler) | ||
882 | 73 | { | ||
883 | 74 | audit_handler_syslog_data_t *data= | ||
884 | 75 | (audit_handler_syslog_data_t*) handler->data; | ||
885 | 76 | MY_STAT stat_arg; | ||
886 | 77 | memset(&stat_arg, 0, sizeof(stat_arg)); | ||
887 | 78 | data->header(&stat_arg, NULL, 0); | ||
888 | 79 | data->footer(NULL, 0); | ||
889 | 80 | return 0; | ||
890 | 81 | } | ||
891 | 82 | |||
892 | 83 | int audit_handler_syslog_close(audit_handler_t *handler) | ||
893 | 84 | { | ||
894 | 85 | audit_handler_syslog_data_t *data= | ||
895 | 86 | (audit_handler_syslog_data_t*) handler->data; | ||
896 | 87 | data->footer(NULL, 0); | ||
897 | 88 | closelog(); | ||
898 | 89 | free(handler); | ||
899 | 90 | return 0; | ||
900 | 91 | } | ||
901 | 92 | 0 | ||
902 | === modified file 'plugin/audit_log/buffer.c' | |||
903 | --- plugin/audit_log/buffer.c 2014-04-21 12:07:45 +0000 | |||
904 | +++ plugin/audit_log/buffer.c 2014-09-26 09:26:38 +0000 | |||
905 | @@ -73,26 +73,25 @@ | |||
906 | 73 | mysql_mutex_unlock(&log->mutex); | 73 | mysql_mutex_unlock(&log->mutex); |
907 | 74 | log->write_func(log->write_func_data, | 74 | log->write_func(log->write_func_data, |
908 | 75 | log->buf + log->flush_pos, | 75 | log->buf + log->flush_pos, |
910 | 76 | log->size - log->flush_pos); | 76 | log->size - log->flush_pos, |
911 | 77 | LOG_RECORD_INCOMPLETE); | ||
912 | 77 | mysql_mutex_lock(&log->mutex); | 78 | mysql_mutex_lock(&log->mutex); |
913 | 78 | log->flush_pos= 0; | 79 | log->flush_pos= 0; |
914 | 79 | log->write_pos%= log->size; | 80 | log->write_pos%= log->size; |
915 | 80 | DBUG_ASSERT(log->write_pos >= log->flush_pos); | ||
916 | 81 | mysql_cond_broadcast(&log->flushed_cond); | ||
917 | 82 | mysql_mutex_unlock(&log->mutex); | ||
918 | 83 | } | 81 | } |
919 | 84 | else | 82 | else |
920 | 85 | { | 83 | { |
921 | 86 | size_t flushlen= log->write_pos - log->flush_pos; | 84 | size_t flushlen= log->write_pos - log->flush_pos; |
922 | 87 | mysql_mutex_unlock(&log->mutex); | 85 | mysql_mutex_unlock(&log->mutex); |
923 | 88 | log->write_func(log->write_func_data, | 86 | log->write_func(log->write_func_data, |
925 | 89 | log->buf + log->flush_pos, flushlen); | 87 | log->buf + log->flush_pos, flushlen, |
926 | 88 | LOG_RECORD_COMPLETE); | ||
927 | 90 | mysql_mutex_lock(&log->mutex); | 89 | mysql_mutex_lock(&log->mutex); |
928 | 91 | log->flush_pos+= flushlen; | 90 | log->flush_pos+= flushlen; |
929 | 92 | DBUG_ASSERT(log->write_pos >= log->flush_pos); | ||
930 | 93 | mysql_cond_broadcast(&log->flushed_cond); | ||
931 | 94 | mysql_mutex_unlock(&log->mutex); | ||
932 | 95 | } | 91 | } |
933 | 92 | DBUG_ASSERT(log->write_pos >= log->flush_pos); | ||
934 | 93 | mysql_cond_broadcast(&log->flushed_cond); | ||
935 | 94 | mysql_mutex_unlock(&log->mutex); | ||
936 | 96 | } | 95 | } |
937 | 97 | 96 | ||
938 | 98 | 97 | ||
939 | 99 | 98 | ||
940 | === modified file 'plugin/audit_log/buffer.h' | |||
941 | --- plugin/audit_log/buffer.h 2014-08-22 13:31:49 +0000 | |||
942 | +++ plugin/audit_log/buffer.h 2014-09-26 09:26:38 +0000 | |||
943 | @@ -19,6 +19,7 @@ | |||
944 | 19 | #define AUDIT_LOG_BUFFER_INCLUDED | 19 | #define AUDIT_LOG_BUFFER_INCLUDED |
945 | 20 | 20 | ||
946 | 21 | #include <string.h> // for size_t | 21 | #include <string.h> // for size_t |
947 | 22 | #include "logger.h" | ||
948 | 22 | 23 | ||
949 | 23 | #ifdef __cplusplus | 24 | #ifdef __cplusplus |
950 | 24 | extern "C" { | 25 | extern "C" { |
951 | @@ -26,7 +27,8 @@ | |||
952 | 26 | 27 | ||
953 | 27 | typedef struct audit_log_buffer audit_log_buffer_t; | 28 | typedef struct audit_log_buffer audit_log_buffer_t; |
954 | 28 | 29 | ||
956 | 29 | typedef int (*audit_log_write_func)(void *data, const char *buf, size_t len); | 30 | typedef int (*audit_log_write_func)(void *data, const char *buf, size_t len, |
957 | 31 | log_record_state_t state); | ||
958 | 30 | 32 | ||
959 | 31 | audit_log_buffer_t *audit_log_buffer_init(size_t size, int drop_if_full, | 33 | audit_log_buffer_t *audit_log_buffer_init(size_t size, int drop_if_full, |
960 | 32 | audit_log_write_func write_func, void *data); | 34 | audit_log_write_func write_func, void *data); |
961 | 33 | 35 | ||
962 | === modified file 'plugin/audit_log/file_logger.c' | |||
963 | --- plugin/audit_log/file_logger.c 2014-07-30 17:12:20 +0000 | |||
964 | +++ plugin/audit_log/file_logger.c 2014-09-26 09:26:38 +0000 | |||
965 | @@ -279,24 +279,28 @@ | |||
966 | 279 | } | 279 | } |
967 | 280 | 280 | ||
968 | 281 | 281 | ||
970 | 282 | int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size) | 282 | int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size, |
971 | 283 | log_record_state_t state) | ||
972 | 283 | { | 284 | { |
973 | 284 | int result; | 285 | int result; |
974 | 285 | my_off_t filesize; | 286 | my_off_t filesize; |
975 | 286 | 287 | ||
976 | 287 | flogger_mutex_lock(log); | 288 | flogger_mutex_lock(log); |
977 | 288 | if (log->rotations > 0) | ||
978 | 289 | if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 || | ||
979 | 290 | ((unsigned long long)filesize >= log->size_limit && | ||
980 | 291 | do_rotate(log))) | ||
981 | 292 | { | ||
982 | 293 | result= -1; | ||
983 | 294 | errno= my_errno; | ||
984 | 295 | goto exit; /* Log rotation needed but failed */ | ||
985 | 296 | } | ||
986 | 297 | 289 | ||
987 | 298 | result= my_write(log->file, (uchar *) buffer, size, MYF(0)); | 290 | result= my_write(log->file, (uchar *) buffer, size, MYF(0)); |
988 | 299 | 291 | ||
989 | 292 | if (state == LOG_RECORD_COMPLETE && log->rotations > 0) | ||
990 | 293 | { | ||
991 | 294 | if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 || | ||
992 | 295 | ((unsigned long long)filesize >= log->size_limit && | ||
993 | 296 | do_rotate(log))) | ||
994 | 297 | { | ||
995 | 298 | result= -1; | ||
996 | 299 | errno= my_errno; | ||
997 | 300 | goto exit; /* Log rotation needed but failed */ | ||
998 | 301 | } | ||
999 | 302 | } | ||
1000 | 303 | |||
1001 | 300 | exit: | 304 | exit: |
1002 | 301 | flogger_mutex_unlock(log); | 305 | flogger_mutex_unlock(log); |
1003 | 302 | return result; | 306 | return result; |
1004 | 303 | 307 | ||
1005 | === modified file 'plugin/audit_log/logger.h' | |||
1006 | --- plugin/audit_log/logger.h 2014-08-22 13:31:49 +0000 | |||
1007 | +++ plugin/audit_log/logger.h 2014-09-26 09:26:38 +0000 | |||
1008 | @@ -62,6 +62,10 @@ | |||
1009 | 62 | typedef struct logger_handle_st LOGGER_HANDLE; | 62 | typedef struct logger_handle_st LOGGER_HANDLE; |
1010 | 63 | typedef size_t (*logger_prolog_func_t)(MY_STAT *, char *buf, size_t buflen); | 63 | typedef size_t (*logger_prolog_func_t)(MY_STAT *, char *buf, size_t buflen); |
1011 | 64 | typedef size_t (*logger_epilog_func_t)(char *buf, size_t buflen); | 64 | typedef size_t (*logger_epilog_func_t)(char *buf, size_t buflen); |
1012 | 65 | typedef enum { | ||
1013 | 66 | LOG_RECORD_COMPLETE, | ||
1014 | 67 | LOG_RECORD_INCOMPLETE | ||
1015 | 68 | } log_record_state_t; | ||
1016 | 65 | 69 | ||
1017 | 66 | void logger_init_mutexes(); | 70 | void logger_init_mutexes(); |
1018 | 67 | LOGGER_HANDLE *logger_open(const char *path, | 71 | LOGGER_HANDLE *logger_open(const char *path, |
1019 | @@ -72,7 +76,8 @@ | |||
1020 | 72 | int logger_close(LOGGER_HANDLE *log, logger_epilog_func_t footer); | 76 | int logger_close(LOGGER_HANDLE *log, logger_epilog_func_t footer); |
1021 | 73 | int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); | 77 | int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); |
1022 | 74 | int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); | 78 | int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); |
1024 | 75 | int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); | 79 | int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size, |
1025 | 80 | log_record_state_t state); | ||
1026 | 76 | int logger_rotate(LOGGER_HANDLE *log); | 81 | int logger_rotate(LOGGER_HANDLE *log); |
1027 | 77 | int logger_sync(LOGGER_HANDLE *log); | 82 | int logger_sync(LOGGER_HANDLE *log); |
1028 | 78 | int logger_reopen(LOGGER_HANDLE *log, logger_prolog_func_t header, | 83 | int logger_reopen(LOGGER_HANDLE *log, logger_prolog_func_t header, |
http:// jenkins. percona. com/view/ PS%205. 6/job/percona- server- 5.6-param/ 705/