diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-14 15:28:51 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-14 17:54:41 +0300 |
commit | f035194d7d1b6cc0846ad7a5d86e0d6fa9463c67 (patch) | |
tree | 494d180cee9a078727c8d4965caa65cb2052f33d /src | |
parent | 58f7dbc0658b3d73816a1bc91b75c2bdac733510 (diff) | |
download | vmod-binlog-f035194d7d1b6cc0846ad7a5d86e0d6fa9463c67.tar.gz vmod-binlog-f035194d7d1b6cc0846ad7a5d86e0d6fa9463c67.tar.bz2 |
New utility binlogsel
* configure.ac: Check for yacc.
* src/.gitignore: Update.
* src/Makefile.am (libbinlog_a_SOURCES): Add new files.
Build binlogsel.
* src/binlogcat.c: Use xmalloc.
* src/binlogsel.c: New file.
* src/parse-datetime.h: New file.
* src/parse-datetime.y: New file.
* src/xalloc.c: New file.
* src/xalloc.h: New file.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 2 | ||||
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/binlogcat.c | 17 | ||||
-rw-r--r-- | src/binlogsel.c | 474 | ||||
-rw-r--r-- | src/parse-datetime.h | 3 | ||||
-rw-r--r-- | src/parse-datetime.y | 1598 | ||||
-rw-r--r-- | src/xalloc.c | 53 | ||||
-rw-r--r-- | src/xalloc.h | 3 |
8 files changed, 2144 insertions, 15 deletions
diff --git a/src/.gitignore b/src/.gitignore index a75fe6d..8f5a6ab 100644 --- a/src/.gitignore +++ b/src/.gitignore | |||
@@ -1,3 +1,5 @@ | |||
1 | binlogcat | 1 | binlogcat |
2 | binlogsel | ||
3 | parse-datetime.c | ||
2 | vcc_if.c | 4 | vcc_if.c |
3 | vcc_if.h | 5 | vcc_if.h |
diff --git a/src/Makefile.am b/src/Makefile.am index 4e31e89..565444a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -14,32 +14,35 @@ | |||
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) | 17 | AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) |
18 | 18 | ||
19 | noinst_LIBRARIES = libbinlog.a | 19 | noinst_LIBRARIES = libbinlog.a |
20 | libbinlog_a_SOURCES = pack.c err.c | 20 | libbinlog_a_SOURCES = pack.c err.c parse-datetime.y xalloc.c |
21 | libbinlog_a_CFLAGS = $(AM_CFLAGS) | 21 | libbinlog_a_CFLAGS = $(AM_CFLAGS) |
22 | 22 | ||
23 | bin_PROGRAMS = binlogcat | 23 | bin_PROGRAMS = binlogcat binlogsel |
24 | binlogcat_SOURCES = binlogcat.c | 24 | binlogcat_SOURCES = binlogcat.c |
25 | binlogcat_LDADD = ./libbinlog.a | 25 | binlogcat_LDADD = ./libbinlog.a |
26 | 26 | ||
27 | binlogsel_SOURCES = binlogsel.c | ||
28 | binlogsel_LDADD = ./libbinlog.a | ||
29 | |||
27 | vmoddir = $(VMODDIR) | 30 | vmoddir = $(VMODDIR) |
28 | vmod_LTLIBRARIES = libvmod_binlog.la | 31 | vmod_LTLIBRARIES = libvmod_binlog.la |
29 | 32 | ||
30 | libvmod_binlog_la_LDFLAGS = -module -export-dynamic -avoid-version | 33 | libvmod_binlog_la_LDFLAGS = -module -export-dynamic -avoid-version |
31 | libvmod_binlog_la_LIBADD= | 34 | libvmod_binlog_la_LIBADD= |
32 | 35 | ||
33 | libvmod_binlog_la_SOURCES = \ | 36 | libvmod_binlog_la_SOURCES = \ |
34 | binlog.c\ | 37 | binlog.c\ |
35 | pack.c\ | 38 | pack.c\ |
36 | vmod-binlog.h\ | 39 | vmod-binlog.h\ |
37 | vcc_if.c vcc_if.h | 40 | vcc_if.c vcc_if.h |
38 | 41 | ||
39 | noinst_HEADERS = pack.h err.h | 42 | noinst_HEADERS = pack.h err.h parse-datetime.h xalloc.h |
40 | 43 | ||
41 | BUILT_SOURCES = vcc_if.c vcc_if.h | 44 | BUILT_SOURCES = vcc_if.c vcc_if.h |
42 | 45 | ||
43 | vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc | 46 | vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc |
44 | @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc | 47 | @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc |
45 | 48 | ||
diff --git a/src/binlogcat.c b/src/binlogcat.c index 505bbc2..656d8f2 100644 --- a/src/binlogcat.c +++ b/src/binlogcat.c | |||
@@ -24,12 +24,13 @@ | |||
24 | #include <errno.h> | 24 | #include <errno.h> |
25 | #include <time.h> | 25 | #include <time.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include "vmod-binlog.h" | 27 | #include "vmod-binlog.h" |
28 | #include "pack.h" | 28 | #include "pack.h" |
29 | #include "err.h" | 29 | #include "err.h" |
30 | #include "xalloc.h" | ||
30 | 31 | ||
31 | char *timefmt = "%c"; | 32 | char *timefmt = "%c"; |
32 | int number_option; | 33 | int number_option; |
33 | int verbose_option; | 34 | int verbose_option; |
34 | int timediff_option; | 35 | int timediff_option; |
35 | 36 | ||
@@ -72,17 +73,13 @@ catlog(const char *fname) | |||
72 | if (header.version != BINLOG_VERSION) { | 73 | if (header.version != BINLOG_VERSION) { |
73 | error("%s: unknown version", fname); | 74 | error("%s: unknown version", fname); |
74 | exit(1); | 75 | exit(1); |
75 | } | 76 | } |
76 | 77 | ||
77 | size = header.hdrsize - sizeof(header); | 78 | size = header.hdrsize - sizeof(header); |
78 | dataspec = malloc(size); | 79 | dataspec = xmalloc(size); |
79 | if (!dataspec) { | ||
80 | error("not enough memory"); | ||
81 | abort(); | ||
82 | } | ||
83 | 80 | ||
84 | if (fread(dataspec, size, 1, fp) != 1) { | 81 | if (fread(dataspec, size, 1, fp) != 1) { |
85 | error("error reading header of %s: %s", | 82 | error("error reading header of %s: %s", |
86 | fname, strerror(errno)); | 83 | fname, strerror(errno)); |
87 | exit(1); | 84 | exit(1); |
88 | } | 85 | } |
@@ -91,26 +88,22 @@ catlog(const char *fname) | |||
91 | printf("# %s; format=%s; recsize=%lu; recnum=%lu\n", | 88 | printf("# %s; format=%s; recsize=%lu; recnum=%lu\n", |
92 | fname, dataspec, header.recsize, header.recnum); | 89 | fname, dataspec, header.recsize, header.recnum); |
93 | 90 | ||
94 | inst = packcomp(dataspec, &p); | 91 | inst = packcomp(dataspec, &p); |
95 | if (!inst) { | 92 | if (!inst) { |
96 | if (errno == EINVAL) { | 93 | if (errno == EINVAL) { |
97 | error("%s: bad dataspec near %s", dataspec, p); | 94 | error("%s: %s: bad dataspec near %s", fname, dataspec, p); |
98 | exit(1); | 95 | exit(1); |
99 | } | 96 | } |
100 | 97 | ||
101 | error("%s", strerror(errno)); | 98 | error("%s", strerror(errno)); |
102 | exit(1); | 99 | exit(1); |
103 | } | 100 | } |
104 | free(dataspec); | 101 | free(dataspec); |
105 | 102 | ||
106 | rec = malloc(header.recsize); | 103 | rec = xmalloc(header.recsize); |
107 | if (!rec) { | ||
108 | error("not enough memory"); | ||
109 | exit(1); | ||
110 | } | ||
111 | env = packenv_create(header.recsize - | 104 | env = packenv_create(header.recsize - |
112 | offsetof(struct binlog_record,data)); | 105 | offsetof(struct binlog_record,data)); |
113 | env->fp = stdout; | 106 | env->fp = stdout; |
114 | 107 | ||
115 | for (i = 0; i < header.recnum; i++) { | 108 | for (i = 0; i < header.recnum; i++) { |
116 | if (fread(rec, header.recsize, 1, fp) != 1) { | 109 | if (fread(rec, header.recsize, 1, fp) != 1) { |
@@ -144,13 +137,13 @@ catlog(const char *fname) | |||
144 | fclose(fp); | 137 | fclose(fp); |
145 | } | 138 | } |
146 | 139 | ||
147 | void | 140 | void |
148 | help() | 141 | help() |
149 | { | 142 | { |
150 | printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n", progname); | 143 | printf("usage: %s [-dhnv] [-t FORMAT] [FILE...]\n", progname); |
151 | } | 144 | } |
152 | 145 | ||
153 | int | 146 | int |
154 | main(int argc, char **argv) | 147 | main(int argc, char **argv) |
155 | { | 148 | { |
156 | int c; | 149 | int c; |
diff --git a/src/binlogsel.c b/src/binlogsel.c new file mode 100644 index 0000000..62299e5 --- /dev/null +++ b/src/binlogsel.c | |||
@@ -0,0 +1,474 @@ | |||
1 | /* This file is part of vmod-binlog | ||
2 | Copyright (C) 2013 Sergey Poznyakoff | ||
3 | |||
4 | Vmod-binlog is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Vmod-binlog is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <config.h> | ||
19 | #include <unistd.h> | ||
20 | #include <sys/stat.h> | ||
21 | #include <sys/mman.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <stddef.h> | ||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <stdarg.h> | ||
27 | #include <errno.h> | ||
28 | #include <time.h> | ||
29 | #include <string.h> | ||
30 | #include <glob.h> | ||
31 | #include "vmod-binlog.h" | ||
32 | #include "pack.h" | ||
33 | #include "err.h" | ||
34 | #include "xalloc.h" | ||
35 | #include "parse-datetime.h" | ||
36 | |||
37 | char *timefmt = "%c"; | ||
38 | int number_option; | ||
39 | int verbose_option; | ||
40 | int timediff_option; | ||
41 | char *pattern; | ||
42 | |||
43 | #define FROM_TIME 0x01 | ||
44 | #define TO_TIME 0x02 | ||
45 | int timemask; | ||
46 | time_t from_time, to_time; | ||
47 | |||
48 | void | ||
49 | help() | ||
50 | { | ||
51 | printf("usage: %s [-dhnv] [-t FORMAT] [-F FROMTIME] [-T TOTIME] [-p PATTERN] [-D DIR] [FILE...]\n", progname); | ||
52 | } | ||
53 | |||
54 | /* Convert strftime-like pattern into globbing pattern */ | ||
55 | void | ||
56 |