From 4adbe0c39415ac0848c4a5e14733369c3bac3a0f Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 21 Nov 2017 22:13:03 +0100 Subject: tools: Fix SEGV in oping client The oping client tried to cancel non-created pthreads if it was killed during flow allocation, which caused a SEGV. The threads are now stopped using a variable. Fixes bug #2. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/tools/oping/oping_client.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index d1d31242..451e5aa0 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -48,6 +48,8 @@ #include #include +volatile bool stop; + void shutdown_client(int signo, siginfo_t * info, void * c) { (void) info; @@ -57,8 +59,7 @@ void shutdown_client(int signo, siginfo_t * info, void * c) case SIGINT: case SIGTERM: case SIGHUP: - pthread_cancel(client.reader_pt); - pthread_cancel(client.writer_pt); + stop = true; default: return; } @@ -79,7 +80,7 @@ void * reader(void * o) fccntl(fd, FLOWSRCVTIMEO, &timeout); - while (client.rcvd != client.count) { + while (!stop && client.rcvd != client.count) { msg_len = flow_read(fd, buf, OPING_BUF_SIZE); if (msg_len == -ETIMEDOUT) break; @@ -149,7 +150,7 @@ void * writer(void * o) pthread_cleanup_push((void (*) (void *)) free, buf); - while (client.sent < client.count) { + while (!stop && client.sent < client.count) { nanosleep(&wait, NULL); clock_gettime(CLOCK_MONOTONIC, &now); @@ -174,6 +175,7 @@ void * writer(void * o) static int client_init(void) { + stop = false; client.sent = 0; client.rcvd = 0; client.rtt_min = FLT_MAX; @@ -228,6 +230,8 @@ static int client_main(void) pthread_create(&client.writer_pt, NULL, writer, &fd); pthread_join(client.writer_pt, NULL); + + pthread_cancel(client.reader_pt); pthread_join(client.reader_pt, NULL); clock_gettime(CLOCK_REALTIME, &toc); -- cgit v1.2.3