Merge lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370 into lp:percona-server/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
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+232843@code.launchpad.net

Description of the change

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

Subscribers

People subscribed via source and target branches