diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2017-11-21 22:13:03 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-11-22 09:57:36 +0100 |
commit | 4adbe0c39415ac0848c4a5e14733369c3bac3a0f (patch) | |
tree | 859728da8acbafae78ddd8685cbb86d140065383 | |
parent | f2a4cc5cca13ff1933b75c6fa7a1491909014ad9 (diff) | |
download | ouroboros-4adbe0c39415ac0848c4a5e14733369c3bac3a0f.tar.gz ouroboros-4adbe0c39415ac0848c4a5e14733369c3bac3a0f.zip |
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 <dimitri.staessens@ugent.be>
Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
-rw-r--r-- | src/tools/oping/oping_client.c | 12 |
1 files 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 <errno.h> #include <float.h> +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); |