summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-12-10 11:48:29 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-12-10 12:01:49 +0100
commit7a8f55bdb4498c927b6f192b83868138b32cce72 (patch)
treef19864ccc41cece2bdc191e49735e9f3dc1bdd72 /src/tools
parent7c2191370c1c4b891df4d1016baeb220ce1d8dca (diff)
downloadouroboros-7a8f55bdb4498c927b6f192b83868138b32cce72.tar.gz
ouroboros-7a8f55bdb4498c927b6f192b83868138b32cce72.zip
tools: Shut down cbr gracefully
Adds a simple cleanup handler that avoids abrupt termination during an sdu_write call, which potentially locks up the entire system due to the writes in the rdrbuff and rbuff not being handled as a single transaction.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/cbr/cbr_client.c36
-rw-r--r--src/tools/cbr/cbr_server.c8
2 files changed, 39 insertions, 5 deletions
diff --git a/src/tools/cbr/cbr_client.c b/src/tools/cbr/cbr_client.c
index 58198b86..8940c9d9 100644
--- a/src/tools/cbr/cbr_client.c
+++ b/src/tools/cbr/cbr_client.c
@@ -24,6 +24,25 @@
#include <ouroboros/dev.h>
#include <ouroboros/time_utils.h>
+#include <signal.h>
+
+volatile bool stop;
+
+static void shutdown_client(int signo, siginfo_t * info, void * c)
+{
+ (void) info;
+ (void) c;
+
+ switch(signo) {
+ case SIGINT:
+ case SIGTERM:
+ case SIGHUP:
+ stop = true;
+ default:
+ return;
+ }
+}
+
static void busy_wait_until(const struct timespec * deadline)
{
struct timespec now;
@@ -42,9 +61,10 @@ int client_main(char * server,
bool flood,
bool sleep)
{
+ struct sigaction sig_act;
+
int fd = 0;
int result = 0;
- bool stop = false;
char buf[size];
long seqnr = 0;
long gap = size * 8.0 * (BILLION / (double) rate);
@@ -54,6 +74,20 @@ int client_main(char * server,
struct timespec intv = {(gap / BILLION), gap % BILLION};
int ms;
+ stop = false;
+
+ memset(&sig_act, 0, sizeof sig_act);
+ sig_act.sa_sigaction = &shutdown_client;
+ sig_act.sa_flags = 0;
+
+ if (sigaction(SIGINT, &sig_act, NULL) ||
+ sigaction(SIGTERM, &sig_act, NULL) ||
+ sigaction(SIGHUP, &sig_act, NULL) ||
+ sigaction(SIGPIPE, &sig_act, NULL)) {
+ printf("Failed to install sighandler.\n");
+ return -1;
+ }
+
printf("Client started, duration %d, rate %lu b/s, size %d B.\n",
duration, rate, size);
diff --git a/src/tools/cbr/cbr_server.c b/src/tools/cbr/cbr_server.c
index d4826e03..104c5e9e 100644
--- a/src/tools/cbr/cbr_server.c
+++ b/src/tools/cbr/cbr_server.c
@@ -46,7 +46,7 @@ int fds_index = 0;
pthread_mutex_t fds_lock;
pthread_cond_t fds_signal;
-void shutdown_server(int signo, siginfo_t * info, void * c)
+static void shutdown_server(int signo, siginfo_t * info, void * c)
{
(void) info;
(void) c;
@@ -61,7 +61,7 @@ void shutdown_server(int signo, siginfo_t * info, void * c)
}
}
-void handle_flow(int fd)
+static void handle_flow(int fd)
{
int count = 0;
char buf[BUF_SIZE];
@@ -125,7 +125,7 @@ void handle_flow(int fd)
flow_dealloc(fd);
}
-void * worker(void * o)
+static void * worker(void * o)
{
int cli_fd;
@@ -153,7 +153,7 @@ void * worker(void * o)
return 0;
}
-void * listener(void * o)
+static void * listener(void * o)
{
int client_fd = 0;
int response = 0;