[master] 3c00c88 Get rid of VUT.name and ask VSM_Name() directly for the name when we need it.

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 6 12:38:06 CEST 2017


commit 3c00c88b652b6adc477e5fa9d3e77fc6bd4c2c48
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 6 10:20:12 2017 +0000

    Get rid of VUT.name and ask VSM_Name() directly for the name when we need it.

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index d82b1ce..bc38a2c 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -45,6 +45,7 @@
 #include "vdef.h"
 #include "vcurses.h"
 #include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vapi/voptget.h"
 #include "vas.h"
 #include "vut.h"
@@ -152,7 +153,7 @@ update(void)
 	if (end_of_file)
 		mvprintw(0, 0, "%*s", COLS - 1, "EOF");
 	else
-		mvprintw(0, 0, "%*s", COLS - 1, VUT.name);
+		mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(VUT.vsm));
 
 	/* count our flock */
 	for (i = 0; i < n; ++i)
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 1911dd3..ca4df6d 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -44,6 +44,7 @@
 
 #include "vcurses.h"
 #include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vapi/voptget.h"
 #include "vas.h"
 #include "vdef.h"
@@ -188,6 +189,7 @@ update(int p)
 	double t = 0;
 	static time_t last = 0;
 	static unsigned n;
+	const char *q;
 	time_t now;
 
 	now = time(NULL);
@@ -199,11 +201,12 @@ update(int p)
 	if (n < p)
 		n++;
 	AC(erase());
+	q = VSM_Name(VUT.vsm);
+	len = COLS - strlen(q);
 	if (end_of_file)
-		AC(mvprintw(0, (COLS - strlen(VUT.name)) - (1 + 6), "%s (EOF)",
-			VUT.name));
+		AC(mvprintw(0, len - (1 + 6), "%s (EOF)", q));
 	else
-		AC(mvprintw(0, (COLS - strlen(VUT.name)) - 1, "%s", VUT.name));
+		AC(mvprintw(0, len - 1, "%s", q));
 	AC(mvprintw(0, 0, "list length %u", ntop));
 	for (tp = VRB_MIN(t_order, &h_order); tp != NULL; tp = tp2) {
 		tp2 = VRB_NEXT(t_order, &h_order, tp);
diff --git a/include/vut.h b/include/vut.h
index 1e1942c..fb9b873 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -35,7 +35,6 @@ typedef int VUT_cb_f(void);
 
 struct VUT {
 	const char	*progname;
-	char		*name;
 
 	/* Options */
 	int		d_opt;
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 83a08da..f9faa10 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -215,7 +215,6 @@ VUT_Init(const char *progname, int argc, char * const *argv,
 		exit(vut_options(voc));
 
 	VUT.progname = progname;
-	REPLACE(VUT.name, "");
 	VUT.g_arg = VSL_g_vxid;
 	AZ(VUT.vsl);
 	VUT.vsl = VSL_New();
@@ -248,7 +247,6 @@ VUT_Setup(void)
 
 	/* Setup input */
 	if (VUT.r_arg) {
-		REPLACE(VUT.name, VUT.r_arg);
 		c = VSL_CursorFile(VUT.vsl, VUT.r_arg, 0);
 		if (c == NULL)
 			VUT_Error(1, "%s", VSL_Error(VUT.vsl));
@@ -257,7 +255,6 @@ VUT_Setup(void)
 		AN(VUT.vsm);
 		if (VUT.n_arg && VSM_n_Arg(VUT.vsm, VUT.n_arg) <= 0)
 			VUT_Error(1, "%s", VSM_Error(VUT.vsm));
-		REPLACE(VUT.name, VSM_Name(VUT.vsm));
 		t_start = NAN;
 		c = NULL;
 		while (1) {
@@ -330,7 +327,6 @@ VUT_Fini(void)
 	free(VUT.n_arg);
 	free(VUT.r_arg);
 	free(VUT.P_arg);
-	free(VUT.name);
 
 	vut_vpf_remove();
 	AZ(VUT.pfh);



More information about the varnish-commit mailing list