[master] d1b78e8 Terminate varnishtop -d automatically

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon May 28 11:08:10 UTC 2018


commit d1b78e8d13a993931d19f2c11acd19959e258ce9
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue May 22 09:57:54 2018 +0200

    Terminate varnishtop -d automatically
    
    Following the documentation, the -d option implies that once processing
    is done the process should exit. We give it the time to do one last
    refresh of the screen in curses mode.
    
    Refs #2686

diff --git a/bin/varnishtest/tests/u00004.vtc b/bin/varnishtest/tests/u00004.vtc
index 4bdc41f..28d58eb 100644
--- a/bin/varnishtest/tests/u00004.vtc
+++ b/bin/varnishtest/tests/u00004.vtc
@@ -12,7 +12,8 @@ client c1 {
 	rxresp
 } -run
 
-shell -expect "fetch" "varnishtop -n ${v1_name} -1 -d"
+shell -expect "fetch" "varnishtop -n ${v1_name} -1"
+shell -expect "fetch" "varnishtop -n ${v1_name} -d"
 
 shell -match "Usage: .*varnishtop <options>" \
 	"varnishtop -h"
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 5f030c9..3035487 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -77,13 +77,13 @@ struct top {
 };
 
 static float period = 60; /* seconds */
-static int end_of_file = 0;
 static unsigned ntop;
 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
 static int f_flag = 0;
 static unsigned maxfieldlen = 0;
 static char *ident;
 
+static volatile sig_atomic_t end_of_file = 0;
 static volatile sig_atomic_t quit = 0;
 
 static VRB_HEAD(t_order, top) h_order = VRB_INITIALIZER(&h_order);
@@ -204,7 +204,7 @@ static void
 update(int p)
 {
 	struct top *tp, *tp2;
-	int l, len;
+	int l, len, eof;
 	double t = 0;
 	static time_t last = 0;
 	static unsigned n;
@@ -222,7 +222,8 @@ update(int p)
 	AC(erase());
 	q = ident;
 	len = COLS - strlen(q);
-	if (end_of_file)
+	eof = end_of_file;
+	if (eof)
 		AC(mvprintw(0, len - (1 + 6), "%s (EOF)", q));
 	else
 		AC(mvprintw(0, len - 1, "%s", q));
@@ -240,7 +241,7 @@ update(int p)
 				len, len, tp->rec_data));
 			t = tp->count;
 		}
-		if (end_of_file)
+		if (eof)
 			continue;
 		tp->count += (1.0/3.0 - tp->count) / (double)n;
 		if (tp->count * 10 < t || l > LINES * 10) {
@@ -252,6 +253,8 @@ update(int p)
 		}
 	}
 	AC(refresh());
+	if (eof)
+		quit = 1;
 }
 
 static void *


More information about the varnish-commit mailing list