aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-14 15:28:51 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-14 17:54:41 +0300
commitf035194d7d1b6cc0846ad7a5d86e0d6fa9463c67 (patch)
tree494d180cee9a078727c8d4965caa65cb2052f33d /src
parent58f7dbc0658b3d73816a1bc91b75c2bdac733510 (diff)
downloadvmod-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/.gitignore2
-rw-r--r--src/Makefile.am9
-rw-r--r--src/binlogcat.c17
-rw-r--r--src/binlogsel.c474
-rw-r--r--src/parse-datetime.h3
-rw-r--r--src/parse-datetime.y1598
-rw-r--r--src/xalloc.c53
-rw-r--r--src/xalloc.h3
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 @@
1binlogcat 1binlogcat
2binlogsel
3parse-datetime.c
2vcc_if.c 4vcc_if.c
3vcc_if.h 5vcc_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
17AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) 17AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
18 18
19noinst_LIBRARIES = libbinlog.a 19noinst_LIBRARIES = libbinlog.a
20libbinlog_a_SOURCES = pack.c err.c 20libbinlog_a_SOURCES = pack.c err.c parse-datetime.y xalloc.c
21libbinlog_a_CFLAGS = $(AM_CFLAGS) 21libbinlog_a_CFLAGS = $(AM_CFLAGS)
22 22
23bin_PROGRAMS = binlogcat 23bin_PROGRAMS = binlogcat binlogsel
24binlogcat_SOURCES = binlogcat.c 24binlogcat_SOURCES = binlogcat.c
25binlogcat_LDADD = ./libbinlog.a 25binlogcat_LDADD = ./libbinlog.a
26 26
27binlogsel_SOURCES = binlogsel.c
28binlogsel_LDADD = ./libbinlog.a
29
27vmoddir = $(VMODDIR) 30vmoddir = $(VMODDIR)
28vmod_LTLIBRARIES = libvmod_binlog.la 31vmod_LTLIBRARIES = libvmod_binlog.la
29 32
30libvmod_binlog_la_LDFLAGS = -module -export-dynamic -avoid-version 33libvmod_binlog_la_LDFLAGS = -module -export-dynamic -avoid-version
31libvmod_binlog_la_LIBADD= 34libvmod_binlog_la_LIBADD=
32 35
33libvmod_binlog_la_SOURCES = \ 36libvmod_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
39noinst_HEADERS = pack.h err.h 42noinst_HEADERS = pack.h err.h parse-datetime.h xalloc.h
40 43
41BUILT_SOURCES = vcc_if.c vcc_if.h 44BUILT_SOURCES = vcc_if.c vcc_if.h
42 45
43vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc 46vcc_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
31char *timefmt = "%c"; 32char *timefmt = "%c";
32int number_option; 33int number_option;
33int verbose_option; 34int verbose_option;
34int timediff_option; 35int 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
147void 140void
148help() 141help()
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
153int 146int
154main(int argc, char **argv) 147main(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
37char *timefmt = "%c";
38int number_option;
39int verbose_option;
40int timediff_option;
41char *pattern;
42
43#define FROM_TIME 0x01
44#define TO_TIME 0x02
45int timemask;
46time_t from_time, to_time;
47
48void
49help()
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 */
55void
56