[5.2] 6ce27bf Signals must be forwarded to VUTs by programs

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


commit 6ce27bf89e7500062f31a600c4835a7602258508
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Sep 5 15:12:14 2017 +0200

    Signals must be forwarded to VUTs by programs
    
    This is a first step away from the global VUT symbol, handled outside of
    VUT_Setup in preparation for the "unglobalization".

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index fbf1f39..bb7dc70 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -484,6 +484,12 @@ profile_error(const char *s)
 	exit(1);
 }
 
+static void
+vut_sighandler(int sig)
+{
+	VUT_Signaled(&VUT, sig);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -608,6 +614,7 @@ main(int argc, char **argv)
 
 	log_ten = log(10.0);
 
+	VUT_Signal(vut_sighandler);
 	VUT_Setup();
 	ident = VSM_Dup(VUT.vsm, "Arg", "-i");
 	if (pthread_create(&thr, NULL, do_curses, NULL) != 0)
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index 3050a6e..ffd1450 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -114,6 +114,12 @@ sighup(void)
 	return (1);
 }
 
+static void
+vut_sighandler(int sig)
+{
+	VUT_Signaled(&VUT, sig);
+}
+
 int
 main(int argc, char * const *argv)
 {
@@ -166,6 +172,7 @@ main(int argc, char * const *argv)
 		LOG.fo = stdout;
 	VUT.idle_f = flushout;
 
+	VUT_Signal(vut_sighandler);
 	VUT_Setup();
 	VUT_Main();
 	VUT_Fini();
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 58f5234..bd20848 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -46,6 +46,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <signal.h>
 #include <stdarg.h>
 #include <inttypes.h>
 #include <limits.h>
@@ -1108,6 +1109,12 @@ sighup(void)
 	return (1);
 }
 
+static void
+vut_sighandler(int sig)
+{
+	VUT_Signaled(&VUT, sig);
+}
+
 static char *
 read_format(const char *formatfile)
 {
@@ -1228,6 +1235,7 @@ main(int argc, char * const *argv)
 		CTX.fo = stdout;
 	VUT.idle_f = flushout;
 
+	VUT_Signal(vut_sighandler);
 	VUT_Setup();
 	VUT_Main();
 	VUT_Fini();
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index a1e70fa..a13ce61 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -34,6 +34,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 5639b22..eb0dd6f 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -185,6 +185,12 @@ sighup(void)
 }
 
 static void
+vut_sighandler(int sig)
+{
+	VUT_Signaled(&VUT, sig);
+}
+
+static void
 update(int p)
 {
 	struct top *tp, *tp2;
@@ -362,6 +368,7 @@ main(int argc, char **argv)
 	if (optind != argc)
 		usage(1);
 
+	VUT_Signal(vut_sighandler);
 	VUT_Setup();
 	ident = VSM_Dup(VUT.vsm, "Arg", "-i");
 	if (!once) {
diff --git a/include/vut.h b/include/vut.h
index b214cdb..d084ec3 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -31,6 +31,7 @@
 
 struct vopt_spec;
 
+typedef void VUT_sighandler_f(int);
 typedef int VUT_cb_f(void);
 
 struct VUT {
@@ -75,6 +76,9 @@ int VUT_Arg(int opt, const char *arg);
 void VUT_Init(const char *progname, int argc, char * const *argv,
     const struct vopt_spec *);
 
+void VUT_Signal(VUT_sighandler_f);
+void VUT_Signaled(struct VUT *, int);
+
 void VUT_Setup(void);
 int  VUT_Main(void);
 void VUT_Fini(void);
diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map
index 0f3fb80..4f23dc5 100644
--- a/lib/libvarnishapi/libvarnishapi.map
+++ b/lib/libvarnishapi/libvarnishapi.map
@@ -134,6 +134,8 @@ LIBVARNISHAPI_2.0 {
 		VUT_Init;
 		VUT_Main;
 		VUT_Setup;
+		VUT_Signal;
+		VUT_Signaled;
 
     local:
 	*;
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 1797dab..d6dbbb9 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -82,15 +82,6 @@ vut_vpf_remove(void)
 	}
 }
 
-static void
-vut_signal(int sig)
-{
-
-	VUT.sighup |= (sig == SIGHUP);
-	VUT.sigint |= (sig == SIGINT || sig == SIGTERM);
-	VUT.sigusr1 |= (sig == SIGUSR1);
-}
-
 static int __match_proto__(VSLQ_dispatch_f)
 vut_dispatch(struct VSL_data *vsl, struct VSL_transaction * const trans[],
     void *priv)
@@ -216,6 +207,27 @@ VUT_Init(const char *progname, int argc, char * const *argv,
 }
 
 void
+VUT_Signal(VUT_sighandler_f sig_cb)
+{
+
+	AN(sig_cb);
+	(void)signal(SIGHUP, sig_cb);
+	(void)signal(SIGINT, sig_cb);
+	(void)signal(SIGTERM, sig_cb);
+	(void)signal(SIGUSR1, sig_cb);
+}
+
+void
+VUT_Signaled(struct VUT *vut, int sig)
+{
+
+	AN(vut);
+	vut->sighup |= (sig == SIGHUP);
+	vut->sigint |= (sig == SIGINT || sig == SIGTERM);
+	vut->sigusr1 |= (sig == SIGUSR1);
+}
+
+void
 VUT_Setup(void)
 {
 	struct VSL_cursor *c;
@@ -254,12 +266,6 @@ VUT_Setup(void)
 		// Cursor is handled in VUT_Main()
 	}
 
-	/* Signal handlers */
-	(void)signal(SIGHUP, vut_signal);
-	(void)signal(SIGINT, vut_signal);
-	(void)signal(SIGTERM, vut_signal);
-	(void)signal(SIGUSR1, vut_signal);
-
 	/* Open PID file */
 	if (VUT.P_arg) {
 		if (pfh != NULL)


More information about the varnish-commit mailing list