[4.0] 8bcefb3 varnishlog -k argument
Lasse Karstensen
lkarsten at varnish-software.com
Wed Oct 8 09:44:39 CEST 2014
commit 8bcefb3ffdd9c6232eaef758fa8b66a10127baf9
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Mon Oct 6 23:58:12 2014 +0200
varnishlog -k argument
Implement -k argument in vut for use with varnishlog. This takes as an
argument the number of log transactions to be processed before
exiting. Useful to stop varnishlog after a given set of log data has
been produced.
Drop -s from the 'not implemented yet' list as this option has very
limited usefullness.
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index aa3bdff..fae84a4 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -59,6 +59,7 @@ VUT_OPT_D
VUT_OPT_g
VUT_OPT_h
VSL_OPT_i
+VUT_OPT_k
VSL_OPT_I
VSL_OPT_L
VUT_OPT_n
diff --git a/doc/sphinx/reference/varnishlog.rst b/doc/sphinx/reference/varnishlog.rst
index b916752..54247fd 100644
--- a/doc/sphinx/reference/varnishlog.rst
+++ b/doc/sphinx/reference/varnishlog.rst
@@ -21,20 +21,6 @@ The following options are available:
.. include:: ../include/varnishlog_options.rst
--k num
-
- Only show the first num log transactions (or log records
- in -g raw mode)
-
- XXX: Not yet implemented
-
--s num
-
- Skip the first num log transactions (or log records if
- in -g raw mode)
-
- XXX: Not yet implemented
-
SIGNALS
=======
diff --git a/include/vut.h b/include/vut.h
index a0b9df2..0dc7482 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -41,6 +41,7 @@ struct VUT {
int d_opt;
int D_opt;
int g_arg;
+ int k_arg;
char *P_arg;
char *q_arg;
char *r_arg;
diff --git a/include/vut_options.h b/include/vut_options.h
index de3bab2..9f01181 100644
--- a/include/vut_options.h
+++ b/include/vut_options.h
@@ -51,6 +51,12 @@
"Print program usage and exit" \
)
+#define VUT_OPT_k \
+ VOPT("k:", "[-k num]", "Limit transactions", \
+ "Process this number of matching log transactions before" \
+ " exiting." \
+ )
+
#define VUT_OPT_n \
VOPT("n:", "[-n name]", "Varnish instance name", \
"Specify the name of the varnishd instance to get logs" \
diff --git a/lib/libvarnishtools/vut.c b/lib/libvarnishtools/vut.c
index 50a9f27..1635ffe 100644
--- a/lib/libvarnishtools/vut.c
+++ b/lib/libvarnishtools/vut.c
@@ -83,6 +83,24 @@ vut_sigusr1(int sig)
VUT.sigusr1 = 1;
}
+static int __match_proto__(VSLQ_dispatch_f)
+vut_dispatch(struct VSL_data *vsl, struct VSL_transaction * const trans[],
+ void *priv)
+{
+ int i;
+
+ (void)priv;
+ if (VUT.k_arg == 0)
+ return (-1); /* End of file */
+ AN(VUT.dispatch_f);
+ i = VUT.dispatch_f(vsl, trans, VUT.dispatch_priv);
+ if (VUT.k_arg > 0)
+ VUT.k_arg--;
+ if (i >= 0 && VUT.k_arg == 0)
+ return (-1); /* End of file */
+ return (i);
+}
+
void
VUT_Error(int status, const char *fmt, ...)
{
@@ -114,6 +132,7 @@ int
VUT_Arg(int opt, const char *arg)
{
int i;
+ char *p;
switch (opt) {
case 'd':
@@ -127,6 +146,12 @@ VUT_Arg(int opt, const char *arg)
case 'g':
/* Grouping */
return (VUT_g_Arg(arg));
+ case 'k':
+ /* Log transaction limit */
+ VUT.k_arg = (int)strtol(arg, &p, 10);
+ if (*p != '\0' || VUT.k_arg <= 0)
+ VUT_Error(1, "-k: Invalid number '%s'", arg);
+ return (1);
case 'n':
/* Varnish instance */
if (VUT.vsm == NULL)
@@ -178,6 +203,7 @@ VUT_Init(const char *progname)
AZ(VUT.vsl);
VUT.vsl = VSL_New();
AN(VUT.vsl);
+ VUT.k_arg = -1;
}
void
@@ -281,8 +307,7 @@ VUT_Main(void)
/* Flush and report any incomplete records */
VUT.sigusr1 = 0;
if (VUT.vslq != NULL)
- VSLQ_Flush(VUT.vslq, VUT.dispatch_f,
- VUT.dispatch_priv);
+ VSLQ_Flush(VUT.vslq, vut_dispatch, NULL);
}
if (VUT.vslq == NULL) {
@@ -307,7 +332,7 @@ VUT_Main(void)
VUT_Error(0, "Log reacquired");
}
- i = VSLQ_Dispatch(VUT.vslq, VUT.dispatch_f, VUT.dispatch_priv);
+ i = VSLQ_Dispatch(VUT.vslq, vut_dispatch, NULL);
if (i == 1)
/* Call again */
continue;
@@ -330,7 +355,7 @@ VUT_Main(void)
/* XXX: Make continuation optional */
- VSLQ_Flush(VUT.vslq, VUT.dispatch_f, VUT.dispatch_priv);
+ VSLQ_Flush(VUT.vslq, vut_dispatch, NULL);
VSLQ_Delete(&VUT.vslq);
AZ(VUT.vslq);
More information about the varnish-commit
mailing list