[master] 475798715 fix signal handling in varnishtop and varnishhist
Nils Goroll
nils.goroll at uplex.de
Fri Oct 11 10:27:07 UTC 2019
commit 475798715cf4f3ce3ef0d129447cf2f342984652
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Fri Oct 11 12:06:10 2019 +0200
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
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 6d441ca6f..8f5dd795d 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -53,6 +53,7 @@
#include "vas.h"
#include "vut.h"
#include "vtim.h"
+#include "vapi/vsig.h"
#define HIST_N 2000 /* how far back we remember */
#define HIST_RES 100 /* bucket resolution */
@@ -131,8 +132,6 @@ static const struct profile profiles[] = {
static const struct profile *active_profile;
-static volatile sig_atomic_t quit = 0;
-
static void
update(void)
{
@@ -384,7 +383,7 @@ do_curses(void *arg)
intrflush(stdscr, FALSE);
curs_set(0);
erase();
- while (!quit && !vut->last_sighup) {
+ while (!VSIG_int && !VSIG_term && !VSIG_hup) {
AZ(pthread_mutex_lock(&mtx));
update();
AZ(pthread_mutex_unlock(&mtx));
@@ -413,7 +412,6 @@ do_curses(void *arg)
case 'Q':
case 'q':
AZ(raise(SIGINT));
- quit = 1;
break;
case '0':
case '1':
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 3bfb9ec56..070b71bd7 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -54,6 +54,7 @@
#include "vas.h"
#include "vtree.h"
#include "vut.h"
+#include "vapi/vsig.h"
#if 0
#define AC(x) assert((x) != ERR)
@@ -82,8 +83,6 @@ static int f_flag = 0;
static unsigned maxfieldlen = 0;
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_key, top) h_key = VRBT_INITIALIZER(&h_key);
@@ -257,7 +256,7 @@ do_curses(void *arg)
(void)curs_set(0);
AC(erase());
timeout(1000);
- while (!quit && !vut->last_sighup) {
+ while (!VSIG_int && !VSIG_term && !VSIG_hup) {
AZ(pthread_mutex_lock(&mtx));
update(period);
AZ(pthread_mutex_unlock(&mtx));
@@ -284,7 +283,6 @@ do_curses(void *arg)
case 'Q':
case 'q':
AZ(raise(SIGINT));
- quit = 1;
break;
default:
AC(beep());
More information about the varnish-commit
mailing list