[master] b214d48 Handle terminal disconnections correctly

Federico G. Schwindt fgsch at lodoss.net
Mon Oct 26 16:52:05 CET 2015


commit b214d4806ed9f63a8bf95db29c176f1da86be13b
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Mon Oct 26 13:54:29 2015 +0000

    Handle terminal disconnections correctly
    
    Change SIGHUP handling depending on whether we're running in daemon mode
    or foreground. The former will continue rotating the logs, the latter
    will abort the loop and die gracefully.
    
    Fixes #1794.

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index aec72e9..9eab9bf 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -291,6 +291,12 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 	return (0);
 }
 
+static int __match_proto__(VUT_cb_f)
+sighup(void)
+{
+	return (1);
+}
+
 static void *
 do_curses(void *arg)
 {
@@ -465,6 +471,7 @@ main(int argc, char **argv)
 	}
 	VUT.dispatch_f = &accumulate;
 	VUT.dispatch_priv = NULL;
+	VUT.sighup_f = sighup;
 	VUT_Main();
 	end_of_file = 1;
 	AZ(pthread_join(thr, NULL));
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index 8e600b5..bc4a915 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -110,6 +110,12 @@ flushout(void)
 	return (0);
 }
 
+static int __match_proto__(VUT_cb_f)
+sighup(void)
+{
+	return (1);
+}
+
 int
 main(int argc, char * const *argv)
 {
@@ -153,10 +159,12 @@ main(int argc, char * const *argv)
 		VUT.dispatch_f = VSL_PrintTransactions;
 	else
 		VUT.dispatch_f = VSL_WriteTransactions;
+	VUT.sighup_f = sighup;
 	if (LOG.w_arg) {
 		openout(LOG.a_opt);
 		AN(LOG.fo);
-		VUT.sighup_f = rotateout;
+		if (VUT.D_opt)
+			VUT.sighup_f = rotateout;
 	} else
 		LOG.fo = stdout;
 	VUT.idle_f = flushout;
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index ed62abd..7b23a6c 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -46,11 +46,11 @@
 	VOPT("w:", "[-w filename]", "Output filename",			\
 	    "Redirect output to file. The file will be overwritten"	\
 	    " unless the -a option was specified. If the application"	\
-	    " receives a SIGHUP the file will be reopened allowing"	\
-	    " the old one to be rotated away. The file can then be"	\
-	    " read by varnishlog and other tools with the -r option,"   \
-	    " unless the -A option was specified. This option is"	\
-	    " required when running in daemon mode."			\
+	    " receives a SIGHUP in daemon mode the file will be "	\
+	    " reopened allowing the old one to be rotated away. The"	\
+	    " file can then be read by varnishlog and other tools with"	\
+	    " the -r option, unless the -A option was specified. This"	\
+	    " option is required when running in daemon mode."		\
 	)
 
 LOG_OPT_a
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 2ee2137..b19b679 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -927,6 +927,12 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 	return (0);
 }
 
+static int __match_proto__(VUT_cb_f)
+sighup(void)
+{
+	return (1);
+}
+
 int
 main(int argc, char * const *argv)
 {
@@ -991,10 +997,12 @@ main(int argc, char * const *argv)
 	/* Setup output */
 	VUT.dispatch_f = &dispatch_f;
 	VUT.dispatch_priv = NULL;
+	VUT.sighup_f = sighup;
 	if (CTX.w_arg) {
 		openout(CTX.a_opt);
 		AN(CTX.fo);
-		VUT.sighup_f = &rotateout;
+		if (VUT.D_opt)
+			VUT.sighup_f = &rotateout;
 	} else
 		CTX.fo = stdout;
 	VUT.idle_f = &flushout;
diff --git a/bin/varnishncsa/varnishncsa_options.h b/bin/varnishncsa/varnishncsa_options.h
index 87075cc..291a1c7 100644
--- a/bin/varnishncsa/varnishncsa_options.h
+++ b/bin/varnishncsa/varnishncsa_options.h
@@ -41,7 +41,7 @@
 	)
 
 #define NCSA_OPT_g							\
-	VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)",		\
+	VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)", \
 	    "The grouping of the log records. The default is to group"	\
 	    " by vxid."							\
 	)
@@ -50,9 +50,9 @@
 	VOPT("w:", "[-w filename]", "Output filename",			\
 	    "Redirect output to file. The file will be overwritten"	\
 	    " unless the -a option was specified. If the application"	\
-	    " receives a SIGHUP the file will be reopened allowing"	\
-	    " the old one to be rotated away. This option is required"	\
-	    " when running in daemon mode."				\
+	    " receives a SIGHUP in daemon mode the file will be"	\
+	    " reopened allowing the old one to be rotated away. This"	\
+	    " option is required when running in daemon mode."		\
 	)
 
 NCSA_OPT_a
diff --git a/bin/varnishtest/tests/u00001.vtc b/bin/varnishtest/tests/u00001.vtc
index 8f35294..1a1c039 100644
--- a/bin/varnishtest/tests/u00001.vtc
+++ b/bin/varnishtest/tests/u00001.vtc
@@ -12,7 +12,7 @@ server s1 {
 
 varnish v1 -vcl+backend "" -start
 
-process p1 "exec ${varnishncsa} -n ${v1_name} -w ${tmpdir}/ncsa.log -F %s" -start
+shell "${varnishncsa} -D -P ${tmpdir}/ncsa.pid -n ${v1_name} -w ${tmpdir}/ncsa.log -F %s"
 
 # give varnishncsa enough time to open the VSM
 delay 2
@@ -27,7 +27,7 @@ delay 2
 
 # rotate logs
 shell "mv ${tmpdir}/ncsa.log ${tmpdir}/ncsa.old.log >/dev/null 2>&1"
-process p1 -kill "HUP"
+shell "kill -HUP `cat ${tmpdir}/ncsa.pid`"
 
 client c1 {
 	txreq -url "/bar"
@@ -37,7 +37,7 @@ client c1 {
 # give varnishncsa enough time to write
 delay 2
 
-process p1 -stop
+shell "kill `cat ${tmpdir}/ncsa.pid`"
 
 shell "grep 200 ${tmpdir}/ncsa.old.log >/dev/null"
 shell "grep 404 ${tmpdir}/ncsa.log >/dev/null"
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 3ab9009..f56b9a7 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -180,6 +180,12 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 	return (0);
 }
 
+static int __match_proto__(VUT_cb_f)
+sighup(void)
+{
+	return (1);
+}
+
 static void
 update(int p)
 {
@@ -362,6 +368,7 @@ main(int argc, char **argv)
 	}
 	VUT.dispatch_f = &accumulate;
 	VUT.dispatch_priv = NULL;
+	VUT.sighup_f = sighup;
 	VUT_Main();
 	end_of_file = 1;
 	if (once)



More information about the varnish-commit mailing list