Commit 47579871 authored by Nils Goroll's avatar Nils Goroll

fix signal handling in varnishtop and varnishhist

Using vut->last_sighup was not adequate, because the VUT_Main loop might
have terminated for some other signal or because of EOF.

On the other hand, we do not want to end the curses loop just because
the VUT_Main loop has ended in order to continue to display the last
state (and maybe the EOF in the top right corner).

So while I see that checking just one flag has some beauty to it, I do
think that directly checking the signal counters is both simple and
robust.

Fixes #3088 for varnishtop and varnishhist
parent 6c510ef7
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "vas.h" #include "vas.h"
#include "vut.h" #include "vut.h"
#include "vtim.h" #include "vtim.h"
#include "vapi/vsig.h"
#define HIST_N 2000 /* how far back we remember */ #define HIST_N 2000 /* how far back we remember */
#define HIST_RES 100 /* bucket resolution */ #define HIST_RES 100 /* bucket resolution */
...@@ -131,8 +132,6 @@ static const struct profile profiles[] = { ...@@ -131,8 +132,6 @@ static const struct profile profiles[] = {
static const struct profile *active_profile; static const struct profile *active_profile;
static volatile sig_atomic_t quit = 0;
static void static void
update(void) update(void)
{ {
...@@ -384,7 +383,7 @@ do_curses(void *arg) ...@@ -384,7 +383,7 @@ do_curses(void *arg)
intrflush(stdscr, FALSE); intrflush(stdscr, FALSE);
curs_set(0); curs_set(0);
erase(); erase();
while (!quit && !vut->last_sighup) { while (!VSIG_int && !VSIG_term && !VSIG_hup) {
AZ(pthread_mutex_lock(&mtx)); AZ(pthread_mutex_lock(&mtx));
update(); update();
AZ(pthread_mutex_unlock(&mtx)); AZ(pthread_mutex_unlock(&mtx));
...@@ -413,7 +412,6 @@ do_curses(void *arg) ...@@ -413,7 +412,6 @@ do_curses(void *arg)
case 'Q': case 'Q':
case 'q': case 'q':
AZ(raise(SIGINT)); AZ(raise(SIGINT));
quit = 1;
break; break;
case '0': case '0':
case '1': case '1':
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "vas.h" #include "vas.h"
#include "vtree.h" #include "vtree.h"
#include "vut.h" #include "vut.h"
#include "vapi/vsig.h"
#if 0 #if 0
#define AC(x) assert((x) != ERR) #define AC(x) assert((x) != ERR)
...@@ -82,8 +83,6 @@ static int f_flag = 0; ...@@ -82,8 +83,6 @@ static int f_flag = 0;
static unsigned maxfieldlen = 0; static unsigned maxfieldlen = 0;
static const char *ident; static const char *ident;
static volatile sig_atomic_t quit = 0;
static VRBT_HEAD(t_order, top) h_order = VRBT_INITIALIZER(&h_order); static VRBT_HEAD(t_order, top) h_order = VRBT_INITIALIZER(&h_order);
static VRBT_HEAD(t_key, top) h_key = VRBT_INITIALIZER(&h_key); static VRBT_HEAD(t_key, top) h_key = VRBT_INITIALIZER(&h_key);
...@@ -257,7 +256,7 @@ do_curses(void *arg) ...@@ -257,7 +256,7 @@ do_curses(void *arg)
(void)curs_set(0); (void)curs_set(0);
AC(erase()); AC(erase());
timeout(1000); timeout(1000);
while (!quit && !vut->last_sighup) { while (!VSIG_int && !VSIG_term && !VSIG_hup) {
AZ(pthread_mutex_lock(&mtx)); AZ(pthread_mutex_lock(&mtx));
update(period); update(period);
AZ(pthread_mutex_unlock(&mtx)); AZ(pthread_mutex_unlock(&mtx));
...@@ -284,7 +283,6 @@ do_curses(void *arg) ...@@ -284,7 +283,6 @@ do_curses(void *arg)
case 'Q': case 'Q':
case 'q': case 'q':
AZ(raise(SIGINT)); AZ(raise(SIGINT));
quit = 1;
break; break;
default: default:
AC(beep()); AC(beep());
......
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