[5.2] 382584e Slightly change VAS so that we always call a function on panic, and let that check if another function is desired.

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Fri Sep 15 11:17:30 UTC 2017


commit 382584eb3e3bf1ae74ec82ead0ed4489453ad733
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Sep 14 16:42:13 2017 +0000

    Slightly change VAS so that we always call a function on panic,
    and let that check if another function is desired.

diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 0d329e1..6601b29 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -691,7 +691,7 @@ PAN_Init(void)
 {
 
 	AZ(pthread_mutex_init(&panicstr_mtx, NULL));
-	VAS_Fail = pan_ic;
+	VAS_Fail_Func = pan_ic;
 	pan_vsb = &pan_vsb_storage;
 	AN(heritage.panic_str);
 	AN(heritage.panic_str_len);
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index df786e8..a764d1f 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -292,7 +292,7 @@ void
 vtc_loginit(char *buf, unsigned buflen)
 {
 
-	VAS_Fail = vtc_log_VAS_Fail;
+	VAS_Fail_Func = vtc_log_VAS_Fail;
 	t0 = VTIM_mono();
 	vtclog_buf = buf;
 	vtclog_left = buflen;
diff --git a/include/vas.h b/include/vas.h
index 591d99e..ec4adc5 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -46,9 +46,11 @@ enum vas_e {
 	VAS_VCL,
 };
 
-typedef void vas_f(const char *, const char *, int, const char *, enum vas_e);
+typedef void vas_f(const char *, const char *, int, const char *, enum vas_e)
+    __attribute__((__noreturn__));
 
-extern vas_f *VAS_Fail __attribute__((__noreturn__));
+extern vas_f *VAS_Fail_Func __attribute__((__noreturn__));
+extern vas_f VAS_Fail __attribute__((__noreturn__));
 
 #ifdef WITHOUT_ASSERTS
 #define assert(e)	((void)(e))
diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/binary_heap.c
index 9799276..beb9a64 100644
--- a/lib/libvarnish/binary_heap.c
+++ b/lib/libvarnish/binary_heap.c
@@ -470,7 +470,7 @@ vasfail(const char *func, const char *file, int line,
 	abort();
 }
 
-vas_f *VAS_Fail = vasfail;
+vas_f *VAS_Fail_Func = vasfail;
 
 struct foo {
 	unsigned	magic;
diff --git a/lib/libvarnish/vas.c b/lib/libvarnish/vas.c
index 0c857a0..3d7f631 100644
--- a/lib/libvarnish/vas.c
+++ b/lib/libvarnish/vas.c
@@ -38,35 +38,39 @@
 
 #include "vas.h"
 
-static void __attribute__((__noreturn__))
-VAS_Fail_default(const char *func, const char *file, int line,
+vas_f *VAS_Fail_Func __attribute__((__noreturn__));
+
+void __attribute__((__noreturn__))
+VAS_Fail(const char *func, const char *file, int line,
     const char *cond, enum vas_e kind)
 {
 	int err = errno;
 
-	if (kind == VAS_MISSING) {
-		fprintf(stderr,
-		    "Missing error handling code in %s(), %s line %d:\n"
-		    "  Condition(%s) not true.\n",
-		    func, file, line, cond);
-	} else if (kind == VAS_INCOMPLETE) {
-		fprintf(stderr,
-		    "Incomplete code in %s(), %s line %d:\n",
-		    func, file, line);
-	} else if (kind == VAS_WRONG) {
-		fprintf(stderr,
-		    "Wrong turn in %s(), %s line %d: %s\n",
-		    func, file, line, cond);
+	if (VAS_Fail_Func != NULL) {
+		VAS_Fail_Func(func, file, line, cond, kind);
 	} else {
-		fprintf(stderr,
-		    "Assert error in %s(), %s line %d:\n"
-		    "  Condition(%s) not true.\n",
-		    func, file, line, cond);
+		if (kind == VAS_MISSING) {
+			fprintf(stderr,
+			    "Missing error handling code in %s(), %s line %d:\n"
+			    "  Condition(%s) not true.\n",
+			    func, file, line, cond);
+		} else if (kind == VAS_INCOMPLETE) {
+			fprintf(stderr,
+			    "Incomplete code in %s(), %s line %d:\n",
+			    func, file, line);
+		} else if (kind == VAS_WRONG) {
+			fprintf(stderr,
+			    "Wrong turn in %s(), %s line %d: %s\n",
+			    func, file, line, cond);
+		} else {
+			fprintf(stderr,
+			    "Assert error in %s(), %s line %d:\n"
+			    "  Condition(%s) not true.\n",
+			    func, file, line, cond);
+		}
+		if (err)
+			fprintf(stderr,
+			    "  errno = %d (%s)\n", err, strerror(err));
 	}
-	if (err)
-		fprintf(stderr,
-		    "  errno = %d (%s)\n", err, strerror(err));
 	abort();
 }
-
-vas_f *VAS_Fail __attribute__((__noreturn__)) = VAS_Fail_default;
diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map
index 7454f4f..4cc3b50 100644
--- a/lib/libvarnishapi/libvarnishapi.map
+++ b/lib/libvarnishapi/libvarnishapi.map
@@ -30,6 +30,7 @@ LIBVARNISHAPI_2.0 {
     global:
 	# vas.c
 		VAS_Fail;
+		VAS_Fail_Func;
 
 	# vcli.c
 		VCLI_AuthResponse;


More information about the varnish-commit mailing list