[master] fd76408f5 varnishlog: New -u option for unbuffered output

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jan 18 16:06:08 UTC 2021


commit fd76408f5bee70447ef9b863385832d0b85748bb
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Nov 23 14:57:56 2020 +0100

    varnishlog: New -u option for unbuffered output
    
    The option was present in libvarnishapi but never exposed.

diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index d9c5170f3..0e049f003 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -60,6 +60,7 @@ static struct log {
 	/* Options */
 	int		a_opt;
 	int		A_opt;
+	int		u_opt;
 	char		*w_arg;
 
 	/* State */
@@ -74,7 +75,7 @@ openout(int append)
 	if (LOG.A_opt)
 		LOG.fo = fopen(LOG.w_arg, append ? "a" : "w");
 	else
-		LOG.fo = VSL_WriteOpen(vut->vsl, LOG.w_arg, append, 0);
+		LOG.fo = VSL_WriteOpen(vut->vsl, LOG.w_arg, append, LOG.u_opt);
 	if (LOG.fo == NULL)
 		VUT_Error(vut, 2, "Cannot open output file (%s)",
 		    LOG.A_opt ? strerror(errno) : VSL_Error(vut->vsl));
@@ -127,6 +128,10 @@ main(int argc, char * const *argv)
 		case 'h':
 			/* Usage help */
 			VUT_Usage(vut, &vopt_spec, 0);
+		case 'u':
+			/* Unbuffered output */
+			LOG.u_opt = 1;
+			break;
 		case 'w':
 			/* Write to file */
 			REPLACE(LOG.w_arg, optarg);
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index 046808663..470023060 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -44,6 +44,12 @@
 	    " data in ascii format."					\
 	)
 
+#define LOG_OPT_u							\
+	VOPT("u", "[-u]", "Unbuffered output",				\
+	    "When writing output to a file with the -w option, output"	\
+	    " data is not buffered."					\
+	)
+
 #define LOG_OPT_w							\
 	VOPT("w:", "[-w <filename>]", "Output filename",		\
 	    "Redirect output to file. The file will be overwritten"	\
@@ -77,6 +83,7 @@ VUT_OPT_r
 VSL_OPT_R
 VUT_OPT_t
 VSL_OPT_T
+LOG_OPT_u
 VSL_OPT_v
 VUT_GLOBAL_OPT_V
 LOG_OPT_w


More information about the varnish-commit mailing list