summaryrefslogtreecommitdiff
path: root/flowtop.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-03-19 02:02:44 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-03-20 17:53:15 +0100
commit451275470106024f106a310a5af050b3ca046a4f (patch)
tree291cfa92cf4e06a0d3a10e7721a3913c2ec90538 /flowtop.c
parent3dfaab495b62658b88a1ed201b2ed61aea34570d (diff)
flowtop: Don't init screen until collector is ready
In case if main thread already initialized screen but then collector called panic, the process exits but console stays with the same colored screen and shifted shell prompt. Fixed by adding conditional variable locking. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'flowtop.c')
-rw-r--r--flowtop.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/flowtop.c b/flowtop.c
index 2db5772..33a110c 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -80,6 +80,7 @@ struct flow_list {
static volatile sig_atomic_t sigint = 0;
static int what = INCLUDE_IPV4 | INCLUDE_IPV6 | INCLUDE_TCP, show_src = 0;
static struct flow_list flow_list;
+static struct condlock collector_ready;
static const char *short_options = "vhTUsDIS46u";
static const struct option long_options[] = {
@@ -978,6 +979,8 @@ static void presenter(void)
int skip_lines = 0;
WINDOW *screen;
+ condlock_wait(&collector_ready);
+
lookup_init_ports(PORTS_TCP);
lookup_init_ports(PORTS_UDP);
screen = screen_init(false);
@@ -1104,6 +1107,8 @@ static void *collector(void *null __maybe_unused)
nfct_filter_destroy(filter);
flow_list_init(&flow_list);
+ condlock_signal(&collector_ready);
+
rcu_register_thread();
while (!sigint && ret >= 0)
@@ -1179,12 +1184,16 @@ int main(int argc, char **argv)
init_geoip(1);
+ condlock_init(&collector_ready);
+
ret = pthread_create(&tid, NULL, collector, NULL);
if (ret < 0)
panic("Cannot create phthread!\n");
presenter();
+ condlock_destroy(&collector_ready);
+
destroy_geoip();
return 0;