[master] 89619ad Instead of exiting tell the loop we are quitting
Federico G. Schwindt
fgsch at lodoss.net
Wed Feb 15 01:46:04 CET 2017
commit 89619adbb995f4d397500304a1068f0aabac462b
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Wed Feb 15 00:36:38 2017 +0000
Instead of exiting tell the loop we are quitting
While here rearrange variables to be more consistent.
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 4c22994..edb9044 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -131,6 +131,8 @@ profiles[] = {
static struct profile *active_profile;
+volatile sig_atomic_t quit = 0;
+
static void
update(void)
{
@@ -369,7 +371,8 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
static int __match_proto__(VUT_cb_f)
sighup(void)
{
- exit(1);
+ quit = 1;
+ return (1);
}
static void *
@@ -385,7 +388,7 @@ do_curses(void *arg)
intrflush(stdscr, FALSE);
curs_set(0);
erase();
- for (;;) {
+ while (!quit) {
AZ(pthread_mutex_lock(&mtx));
update();
AZ(pthread_mutex_unlock(&mtx));
@@ -414,7 +417,7 @@ do_curses(void *arg)
case 'q':
raise(SIGINT);
endwin();
- pthread_exit(NULL);
+ return (NULL);
case '0':
case '1':
case '2':
@@ -458,7 +461,8 @@ do_curses(void *arg)
AZ(pthread_mutex_unlock(&mtx));
}
}
- NEEDLESS(pthread_exit(NULL));
+ endwin();
+ return (NULL);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 7addb28..0c08e02 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -61,10 +61,6 @@
#define AC(x) x
#endif
-static const char progname[] = "varnishtop";
-static float period = 60; /* seconds */
-static int end_of_file = 0;
-
struct top {
uint8_t tag;
const char *rec_data;
@@ -76,6 +72,16 @@ struct top {
double count;
};
+static const char progname[] = "varnishtop";
+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;
+
+volatile sig_atomic_t quit = 0;
+
static VRB_HEAD(t_order, top) h_order = VRB_INITIALIZER(&h_order);
static VRB_HEAD(t_key, top) h_key = VRB_INITIALIZER(&h_key);
@@ -101,14 +107,6 @@ cmp_order(const struct top *a, const struct top *b)
return (cmp_key(a, b));
}
-static unsigned ntop;
-
-static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
-
-static int f_flag = 0;
-
-static unsigned maxfieldlen = 0;
-
VRB_PROTOTYPE_STATIC(t_order, top, e_order, cmp_order)
VRB_GENERATE_STATIC(t_order, top, e_order, cmp_order)
VRB_PROTOTYPE_STATIC(t_key, top, e_key, cmp_key)
@@ -183,7 +181,8 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
static int __match_proto__(VUT_cb_f)
sighup(void)
{
- exit (1);
+ quit = 1;
+ return (1);
}
static void
@@ -258,7 +257,7 @@ do_curses(void *arg)
AC(intrflush(stdscr, FALSE));
(void)curs_set(0);
AC(erase());
- for (;;) {
+ while (!quit) {
AZ(pthread_mutex_lock(&mtx));
update(period);
AZ(pthread_mutex_unlock(&mtx));
@@ -287,13 +286,14 @@ do_curses(void *arg)
case 'q':
AZ(raise(SIGINT));
AC(endwin());
- return NULL;
+ return (NULL);
default:
AC(beep());
break;
}
}
- NEEDLESS(return NULL);
+ AC(endwin());
+ return (NULL);
}
static void
More information about the varnish-commit
mailing list