[4.1] 772e716 Move the sigaltstack init to a generic THR_Init() and use it for all threads

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Wed Sep 20 12:34:06 UTC 2017


commit 772e716dc639466b22b6b93410fa1a0f860fdc47
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 11 12:34:32 2017 +0200

    Move the sigaltstack init to a generic THR_Init() and use it for all threads
    
    This is a back port to 4.1, and the conflicts are partly a result of the
    non inclusion of 656982a5cf7042a8576c2e9d48defcd25d749fbd in 4.1.
    
    (Back port by Pål Hermunn Johansen, hermunn at varnish-software.com)
    
    Conflicts:
    	bin/varnishd/cache/cache_pool.c
    	bin/varnishd/cache/cache_wrk.c

diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 5b2827a..d204ff9 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -490,6 +490,7 @@ vca_acct(void *arg)
 	double t0, now;
 
 	THR_SetName("cache-acceptor");
+	THR_Init();
 	(void)arg;
 
 	(void)vca_tcp_opt_init();
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index f0ebf83..d8b1684 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -105,6 +105,22 @@ THR_GetName(void)
 }
 
 /*--------------------------------------------------------------------
+ * Generic setup all our threads should call
+ */
+#ifdef HAVE_SIGALTSTACK
+#include <signal.h>
+extern stack_t altstack;
+#endif
+
+void
+THR_Init(void)
+{
+#ifdef HAVE_SIGALTSTACK
+       AZ(sigaltstack(&altstack, NULL));
+#endif
+}
+
+/*--------------------------------------------------------------------
  * VXID's are unique transaction numbers allocated with a minimum of
  * locking overhead via pools in the worker threads.
  *
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index 472441c..88662d3 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -101,6 +101,7 @@ mpl_guard(void *priv)
 
 	CAST_OBJ_NOTNULL(mpl, priv, MEMPOOL_MAGIC);
 	THR_SetName(mpl->name);
+	THR_Init();
 	mpl_slp = 0.15;	// random
 	while (1) {
 		VTIM_sleep(mpl_slp);
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index 409d2c3..874e0cb 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -190,7 +190,8 @@ pool_poolherder(void *priv)
 	struct pool *pp;
 	uint64_t u;
 
-	THR_SetName("pool_herder");
+	THR_SetName("pool_poolherder");
+	THR_Init();
 	(void)priv;
 
 	nwq = 0;
diff --git a/bin/varnishd/cache/cache_priv.h b/bin/varnishd/cache/cache_priv.h
index 521f569..ef0ea26 100644
--- a/bin/varnishd/cache/cache_priv.h
+++ b/bin/varnishd/cache/cache_priv.h
@@ -96,6 +96,7 @@ void THR_SetBusyobj(const struct busyobj *);
 struct busyobj * THR_GetBusyobj(void);
 void THR_SetRequest(const struct req *);
 struct req * THR_GetRequest(void);
+void THR_Init(void);
 
 /* cache_lck.c */
 void LCK_Init(void);
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 9ede273..2355752 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -41,11 +41,6 @@
 
 #include "hash/hash_slinger.h"
 
-#ifdef HAVE_SIGALTSTACK
-#include <signal.h>
-extern stack_t altstack;
-#endif
-
 static void Pool_Work_Thread(struct pool *pp, struct worker *wrk);
 
 /*--------------------------------------------------------------------
@@ -69,6 +64,7 @@ wrk_bgthread(void *arg)
 
 	CAST_OBJ_NOTNULL(bt, arg, BGTHREAD_MAGIC);
 	THR_SetName(bt->name);
+	THR_Init();
 	INIT_OBJ(&wrk, WORKER_MAGIC);
 
 	(void)bt->func(&wrk, bt->priv);
@@ -403,9 +399,7 @@ pool_thread(void *priv)
 	struct pool_info *pi;
 
 	CAST_OBJ_NOTNULL(pi, priv, POOL_INFO_MAGIC);
-#ifdef HAVE_SIGALTSTACK
-	AZ(sigaltstack(&altstack, NULL));
-#endif
+	THR_Init();
 	WRK_Thread(pi->qp, pi->stacksize, cache_param->workspace_thread);
 	FREE_OBJ(pi);
 	return (NULL);
@@ -477,6 +471,9 @@ pool_herder(void *priv)
 
 	CAST_OBJ_NOTNULL(pp, priv, POOL_MAGIC);
 
+	THR_SetName("pool_herder");
+	THR_Init();
+
 	while (1) {
 		wthread_min = cache_param->wthread_min;
 
diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c
index 68afcb2..71c426a 100644
--- a/bin/varnishd/waiter/cache_waiter_epoll.c
+++ b/bin/varnishd/waiter/cache_waiter_epoll.c
@@ -86,6 +86,7 @@ vwe_thread(void *priv)
 	w = vwe->waiter;
 	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
 	THR_SetName("cache-epoll");
+	THR_Init();
 
 	now = VTIM_real();
 	while (1) {
diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c
index 5518875..ec191a7 100644
--- a/bin/varnishd/waiter/cache_waiter_kqueue.c
+++ b/bin/varnishd/waiter/cache_waiter_kqueue.c
@@ -77,6 +77,7 @@ vwk_thread(void *priv)
 	w = vwk->waiter;
 	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
 	THR_SetName("cache-kqueue");
+	THR_Init();
 
 	now = VTIM_real();
 	while (1) {
diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c
index ed3a39c..6c72cb1 100644
--- a/bin/varnishd/waiter/cache_waiter_poll.c
+++ b/bin/varnishd/waiter/cache_waiter_poll.c
@@ -162,6 +162,7 @@ vwp_main(void *priv)
 	int i;
 
 	THR_SetName("cache-poll");
+	THR_Init();
 	CAST_OBJ_NOTNULL(vwp, priv, VWP_MAGIC);
 	w = vwp->waiter;
 
diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c
index 705e442..499249f 100644
--- a/bin/varnishd/waiter/cache_waiter_ports.c
+++ b/bin/varnishd/waiter/cache_waiter_ports.c
@@ -150,6 +150,7 @@ vws_thread(void *priv)
 	w = vws->waiter;
 	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
 	THR_SetName("cache-ports");
+	THR_Init();
 
 	now = VTIM_real();
 


More information about the varnish-commit mailing list