From b68cb179a9b3e10e5f683d477e0e232e70bf6de2 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Sat, 20 Aug 2011 18:33:47 +0200 Subject: [PATCH] [Client] Handle signals --- TODO | 1 - owlps-client/owlps-client.c | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 5279ed0..7fd9f0a 100644 --- a/TODO +++ b/TODO @@ -59,7 +59,6 @@ * Client -- Handle signals. - Add verbose & quiet options. - Log sent requests? - Allow to use a string for the direction? diff --git a/owlps-client/owlps-client.c b/owlps-client/owlps-client.c index 95ca65d..33c616f 100644 --- a/owlps-client/owlps-client.c +++ b/owlps-client/owlps-client.c @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -88,9 +89,19 @@ uint_fast16_t packet_size ; // Packet size int main(int argc, char *argv[]) { + struct sigaction action ; // Signal handler structure + program_name = argv[0] ; parse_command_line(argc, argv) ; + /* Set up signal handlers */ + action.sa_flags = 0 ; + sigemptyset(&action.sa_mask) ; + action.sa_handler = owl_sigint_handler ; + sigaction(SIGINT, &action, NULL) ; + action.sa_handler = owl_sigterm_handler ; + sigaction(SIGTERM, &action, NULL) ; + create_socket() ; request_transmission: @@ -98,7 +109,7 @@ int main(int argc, char *argv[]) send_request() ; free(packet) ; - if (options.flood_delay >= 0) + if (options.flood_delay >= 0 && owl_run) { usleep(options.flood_delay * 1000) ; goto request_transmission ;