[Client] Handle signals

This commit is contained in:
Matteo Cypriani 2011-08-20 18:33:47 +02:00
parent 8327357290
commit b68cb179a9
2 changed files with 12 additions and 2 deletions

1
TODO
View File

@ -59,7 +59,6 @@
* Client
- Handle signals.
- Add verbose & quiet options.
- Log sent requests?
- Allow to use a string for the direction?

View File

@ -9,6 +9,7 @@
#include <unistd.h>
#include <inttypes.h>
#include <string.h>
#include <signal.h>
#include <net/if.h>
@ -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 ;