[5.2] e821a0b Pass VUTs to callbacks

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


commit e821a0b0de71e2e911870b7a0f4cd44bfc133bbd
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Sep 5 15:28:32 2017 +0200

    Pass VUTs to callbacks
    
    With the exception of dispatch_f that already has a dispatch_priv.

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index bb7dc70..fe2df7a 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -366,8 +366,9 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 }
 
 static int __match_proto__(VUT_cb_f)
-sighup(void)
+sighup(struct VUT *v)
 {
+	assert(v == &VUT);
 	quit = 1;
 	return (1);
 }
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index ffd1450..edabf63 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -87,9 +87,10 @@ openout(int append)
 }
 
 static int __match_proto__(VUT_cb_f)
-rotateout(void)
+rotateout(struct VUT *v)
 {
 
+	assert(v == &VUT);
 	AN(LOG.w_arg);
 	AN(LOG.fo);
 	fclose(LOG.fo);
@@ -99,9 +100,11 @@ rotateout(void)
 }
 
 static int __match_proto__(VUT_cb_f)
-flushout(void)
+flushout(struct VUT *v)
 {
 
+	if (v != NULL)
+		assert(v == &VUT);
 	AN(LOG.fo);
 	if (fflush(LOG.fo))
 		return (-5);
@@ -109,8 +112,9 @@ flushout(void)
 }
 
 static int __match_proto__(VUT_cb_f)
-sighup(void)
+sighup(struct VUT *v)
 {
+	assert(v == &VUT);
 	return (1);
 }
 
@@ -177,7 +181,7 @@ main(int argc, char * const *argv)
 	VUT_Main();
 	VUT_Fini();
 
-	(void)flushout();
+	(void)flushout(NULL);
 
 	exit(0);
 }
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index bd20848..415691e 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -183,9 +183,10 @@ openout(int append)
 }
 
 static int __match_proto__(VUT_cb_f)
-rotateout(void)
+rotateout(struct VUT *v)
 {
 
+	assert(v == &VUT);
 	AN(CTX.w_arg);
 	AN(CTX.fo);
 	fclose(CTX.fo);
@@ -195,9 +196,10 @@ rotateout(void)
 }
 
 static int __match_proto__(VUT_cb_f)
-flushout(void)
+flushout(struct VUT *v)
 {
 
+	assert(v == &VUT);
 	AN(CTX.fo);
 	if (fflush(CTX.fo))
 		return (-5);
@@ -1104,8 +1106,9 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 }
 
 static int __match_proto__(VUT_cb_f)
-sighup(void)
+sighup(struct VUT *v)
 {
+	assert(v == &VUT);
 	return (1);
 }
 
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index eb0dd6f..85d8dab 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -178,8 +178,9 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 }
 
 static int __match_proto__(VUT_cb_f)
-sighup(void)
+sighup(struct VUT *v)
 {
+	assert(v == &VUT);
 	quit = 1;
 	return (1);
 }
diff --git a/include/vut.h b/include/vut.h
index d084ec3..1fbe755 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -29,10 +29,11 @@
  * Common functions for the utilities
  */
 
+struct VUT;
 struct vopt_spec;
 
 typedef void VUT_sighandler_f(int);
-typedef int VUT_cb_f(void);
+typedef int VUT_cb_f(struct VUT *);
 
 struct VUT {
 	const char	*progname;
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index d6dbbb9..5bd24d4 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -324,7 +324,7 @@ VUT_Main(void)
 		if (VUT.sighup && VUT.sighup_f) {
 			/* sighup callback */
 			VUT.sighup = 0;
-			i = VUT.sighup_f();
+			i = VUT.sighup_f(&VUT);
 			if (i)
 				break;
 		}
@@ -370,7 +370,7 @@ VUT_Main(void)
 		else if (i == 0) {
 			/* Nothing to do but wait */
 			if (VUT.idle_f) {
-				i = VUT.idle_f();
+				i = VUT.idle_f(&VUT);
 				if (i)
 					break;
 			}


More information about the varnish-commit mailing list