From a8c5a9787ba4e8757b16505409c4fbe7d7549e18 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 4 Aug 2016 20:34:56 +0200 Subject: tools: cbr: Fix missing check on ap_init If ap_init() fails, the program should exit. --- src/tools/cbr/cbr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/tools') diff --git a/src/tools/cbr/cbr.c b/src/tools/cbr/cbr.c index 0cce50db..65783119 100644 --- a/src/tools/cbr/cbr.c +++ b/src/tools/cbr/cbr.c @@ -75,8 +75,10 @@ int main(int argc, char ** argv) bool server = false; - /* FIXME: should be argv[0] */ - ap_init(argv[0]); + if (ap_init(argv[0]) < 0) { + printf("Failed to init.\n"); + exit(EXIT_FAILURE); + } server_settings.interval = 1; /* One second reporting interval */ server_settings.timeout = 1; -- cgit v1.2.3 From 432e93affce4d5ddcc816f826268bc68d5789756 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 4 Aug 2016 20:51:09 +0200 Subject: tools: cbr: Fix server cleanup The server should cleanup whenever the listen thread exits. --- src/tools/cbr/cbr_server.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/tools') diff --git a/src/tools/cbr/cbr_server.c b/src/tools/cbr/cbr_server.c index 1890c842..fc23363f 100644 --- a/src/tools/cbr/cbr_server.c +++ b/src/tools/cbr/cbr_server.c @@ -47,18 +47,11 @@ pthread_cond_t fds_signal; void shutdown_server(int signo, siginfo_t * info, void * c) { - int i; - switch(signo) { case SIGINT: case SIGTERM: case SIGHUP: pthread_cancel(listen_thread); - - for (i = 0; i < THREADS_SIZE; i++) { - pthread_cancel(threads[i]); - } - default: return; } @@ -226,19 +219,18 @@ int server_main() exit(EXIT_FAILURE); } - for (i = 0; i < THREADS_SIZE; i++) { - pthread_create(&threads[i], NULL, - worker, NULL); - } + for (i = 0; i < THREADS_SIZE; i++) + pthread_create(&threads[i], NULL, worker, NULL); - pthread_create(&listen_thread, NULL, - listener, NULL); + pthread_create(&listen_thread, NULL, listener, NULL); pthread_join(listen_thread, NULL); - for (i = 0; i < THREADS_SIZE; i++) { + for (i = 0; i < THREADS_SIZE; i++) + pthread_cancel(threads[i]); + + for (i = 0; i < THREADS_SIZE; i++) pthread_join(threads[i], NULL); - } return 0; } -- cgit v1.2.3 From 7e78d3f2fb1d3203aff64e72589cf98649e4fada Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 4 Aug 2016 21:01:28 +0200 Subject: tools: oping: Fix cleanup on exit The server should cleanup whenever the listen thread exits. --- src/tools/oping/oping_server.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c index eb0b511b..a5021cba 100644 --- a/src/tools/oping/oping_server.c +++ b/src/tools/oping/oping_server.c @@ -37,9 +37,7 @@ void shutdown_server(int signo, siginfo_t * info, void * c) case SIGINT: case SIGTERM: case SIGHUP: - pthread_cancel(server.server_pt); pthread_cancel(server.accept_pt); - pthread_cancel(server.cleaner_pt); default: return; } @@ -154,8 +152,12 @@ int server_main() pthread_create(&server.accept_pt, NULL, accept_thread, NULL); pthread_create(&server.server_pt, NULL, server_thread, NULL); - pthread_join(server.server_pt, NULL); pthread_join(server.accept_pt, NULL); + + pthread_cancel(server.server_pt); + pthread_cancel(server.cleaner_pt); + + pthread_join(server.server_pt, NULL); pthread_join(server.cleaner_pt, NULL); return 0; -- cgit v1.2.3 From 00761652fb55e16227508457da4bda82b19ef193 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 4 Aug 2016 21:27:45 +0200 Subject: tools: oping: Fix client cleanup --- src/tools/oping/oping_client.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/tools') diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index 7693ce41..b47eee6c 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -132,12 +132,15 @@ void * writer(void * o) printf("Pinging %s with %d bytes of data:\n\n", client.s_apn, client.size); + pthread_cleanup_push((void (*) (void *)) free, buf); + while (client.sent < client.count) { nanosleep(&wait, NULL); msg->id = htonl(client.sent); if (flow_write(*fdp, buf, client.size) == -1) { printf("Failed to send SDU.\n"); flow_dealloc(*fdp); + free(buf); return (void *) -1; } @@ -148,6 +151,8 @@ void * writer(void * o) pthread_mutex_unlock(&client.lock); } + pthread_cleanup_pop(true); + return (void *) 0; } -- cgit v1.2.3 From 656fb082a3ab596555ba661ee98ab8400f9dd4f1 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 6 Aug 2016 02:46:15 +0200 Subject: tools: oping: Fix wrong delay calculation --- src/tools/oping/oping_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/tools') diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index b47eee6c..0d4a10af 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -115,7 +115,8 @@ void * writer(void * o) { int * fdp = (int *) o; struct timespec now; - struct timespec wait = {client.interval / 1000, client.interval % 1000}; + struct timespec wait = {client.interval / 1000, + (client.interval % 1000) * MILLION}; struct oping_msg * msg; char * buf = malloc(client.size); -- cgit v1.2.3