[master] 1d327ef32 Make VSM_Attach interruptible

Federico G. Schwindt fgsch at lodoss.net
Tue Nov 13 21:49:09 UTC 2018


commit 1d327ef32b2a452d9ae782839f48617eb1bb4db1
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Tue Nov 13 12:59:35 2018 +0900

    Make VSM_Attach interruptible
    
    Fixes #2657.

diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c
index d909ebd24..b7b82cbf5 100644
--- a/bin/varnishadm/varnishadm.c
+++ b/bin/varnishadm/varnishadm.c
@@ -59,6 +59,7 @@
 
 #include "vdef.h"
 
+#include "vapi/vsig.h"
 #include "vapi/vsm.h"
 #include "vas.h"
 #include "vcli.h"
@@ -472,6 +473,9 @@ main(int argc, char * const *argv)
 	argc -= optind;
 	argv += optind;
 
+	VSIG_Arm_int();
+	VSIG_Arm_term();
+
 	if (T_arg != NULL) {
 		if (n_arg != NULL)
 			usage(1);
diff --git a/bin/varnishtest/tests/u00003.vtc b/bin/varnishtest/tests/u00003.vtc
index bc86232bb..30dc846e1 100644
--- a/bin/varnishtest/tests/u00003.vtc
+++ b/bin/varnishtest/tests/u00003.vtc
@@ -154,3 +154,8 @@ process p1 -expect-text 1 0 {/1?foo=bar HTTP/1.1" 200 100 "-" "-"}
 process p1 -expect-text 1 0 { - user [}
 process p1 -expect-text 2 0 {/1?foo=bar HTTP/1.1" 404 248 "-" "-"}
 process p1 -expect-text 3 0 {/2 HTTP/1.1" - - "-" "-"}
+
+process p2 {varnishncsa -t 5 -n nonexistent} -start
+delay 1
+process p2 -expect-exit 1 -kill INT -wait
+shell {grep -q "VSM: Attach interrupted" ${p2_err}}
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index 7380bbae3..f10c77e36 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -55,6 +55,7 @@
 #include "vqueue.h"
 #include "vtim.h"
 
+#include "vapi/vsig.h"
 #include "vapi/vsm.h"
 
 #ifndef MAP_HASSEMAPHORE
@@ -676,7 +677,7 @@ VSM_Attach(struct vsm *vd, int progress)
 	}
 
 	AZ(vd->attached);
-	while (1) {
+	while (!VSIG_int && !VSIG_term) {
 		u = VSM_Status(vd);
 		VSM_ResetError(vd);
 		if (u & VSM_MGT_RUNNING) {
@@ -695,6 +696,7 @@ VSM_Attach(struct vsm *vd, int progress)
 			(void)write(progress, ".", 1);
 		VTIM_sleep(.25);
 	}
+	return (vsm_diag(vd, "Attach interrupted"));
 }
 
 /*--------------------------------------------------------------------*/


More information about the varnish-commit mailing list