Commit d1b78e8d authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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
parent c14650ca
...@@ -12,7 +12,8 @@ client c1 { ...@@ -12,7 +12,8 @@ client c1 {
rxresp rxresp
} -run } -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>" \ shell -match "Usage: .*varnishtop <options>" \
"varnishtop -h" "varnishtop -h"
......
...@@ -77,13 +77,13 @@ struct top { ...@@ -77,13 +77,13 @@ struct top {
}; };
static float period = 60; /* seconds */ static float period = 60; /* seconds */
static int end_of_file = 0;
static unsigned ntop; static unsigned ntop;
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static int f_flag = 0; static int f_flag = 0;
static unsigned maxfieldlen = 0; static unsigned maxfieldlen = 0;
static char *ident; static char *ident;
static volatile sig_atomic_t end_of_file = 0;
static volatile sig_atomic_t quit = 0; static volatile sig_atomic_t quit = 0;
static VRB_HEAD(t_order, top) h_order = VRB_INITIALIZER(&h_order); static VRB_HEAD(t_order, top) h_order = VRB_INITIALIZER(&h_order);
...@@ -204,7 +204,7 @@ static void ...@@ -204,7 +204,7 @@ static void
update(int p) update(int p)
{ {
struct top *tp, *tp2; struct top *tp, *tp2;
int l, len; int l, len, eof;
double t = 0; double t = 0;
static time_t last = 0; static time_t last = 0;
static unsigned n; static unsigned n;
...@@ -222,7 +222,8 @@ update(int p) ...@@ -222,7 +222,8 @@ update(int p)
AC(erase()); AC(erase());
q = ident; q = ident;
len = COLS - strlen(q); len = COLS - strlen(q);
if (end_of_file) eof = end_of_file;
if (eof)
AC(mvprintw(0, len - (1 + 6), "%s (EOF)", q)); AC(mvprintw(0, len - (1 + 6), "%s (EOF)", q));
else else
AC(mvprintw(0, len - 1, "%s", q)); AC(mvprintw(0, len - 1, "%s", q));
...@@ -240,7 +241,7 @@ update(int p) ...@@ -240,7 +241,7 @@ update(int p)
len, len, tp->rec_data)); len, len, tp->rec_data));
t = tp->count; t = tp->count;
} }
if (end_of_file) if (eof)
continue; continue;
tp->count += (1.0/3.0 - tp->count) / (double)n; tp->count += (1.0/3.0 - tp->count) / (double)n;
if (tp->count * 10 < t || l > LINES * 10) { if (tp->count * 10 < t || l > LINES * 10) {
...@@ -252,6 +253,8 @@ update(int p) ...@@ -252,6 +253,8 @@ update(int p)
} }
} }
AC(refresh()); AC(refresh());
if (eof)
quit = 1;
} }
static void * static void *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment