[master] fe96d9828 Release the panicstr_mtx before calling abort(2), but still protect against reentrancy.

Poul-Henning Kamp phk at FreeBSD.org
Tue Sep 21 08:14:06 UTC 2021


commit fe96d9828b263c903adfd7d4a90e2d7a9abc20cf
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Sep 21 08:12:19 2021 +0000

    Release the panicstr_mtx before calling abort(2), but still protect against reentrancy.
    
    Fixes: #3688

diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 190ac90b7..3d01e6090 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -718,9 +718,11 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 	struct sigaction sa;
 	int err = errno;
 
-	AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
-						  we're going to die
-						  anyway */
+	AZ(pthread_mutex_lock(&panicstr_mtx));
+
+	/* If we already panic'ed, do nothing */
+	while (heritage.panic_str[0])
+		sleep(1);
 
 	/*
 	 * should we trigger a SIGSEGV while handling a panic, our sigsegv
@@ -809,6 +811,7 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 	VSB_putc(pan_vsb, '\0');	/* NUL termination */
 
 	v_gcov_flush();
+	AZ(pthread_mutex_unlock(&panicstr_mtx));
 	abort();
 }
 


More information about the varnish-commit mailing list