From d68d6132daddaa4fe196116a103f485838ec1d61 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Wed, 25 Nov 2009 16:43:17 +0000 Subject: [PATCH] Remove feature to quit the isotptun by keypress (from stdin) as it was not possible to run it from a start-script. Added a signal handler to gracefully leave the isotptun. --- isotptun.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/isotptun.c b/isotptun.c index d40df87..1ea56b9 100644 --- a/isotptun.c +++ b/isotptun.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,8 @@ #define NO_CAN_ID 0xFFFFFFFFU +static volatile int running = 1; + void print_usage(char *prg) { fprintf(stderr, "\nUsage: %s [options] \n\n", prg); @@ -93,6 +96,11 @@ void print_usage(char *prg) fprintf(stderr, "\n"); } +void sigterm(int signo) +{ + running = 0; +} + int main(int argc, char **argv) { fd_set rdfs; @@ -103,12 +111,15 @@ int main(int argc, char **argv) static struct can_isotp_fc_options fcopts; int opt, ret; extern int optind, opterr, optopt; - static int quit; static int verbose; unsigned char buffer[4096]; int nbytes; + signal(SIGTERM, sigterm); + signal(SIGHUP, sigterm); + signal(SIGINT, sigterm); + addr.can_addr.tp.tx_id = addr.can_addr.tp.rx_id = NO_CAN_ID; while ((opt = getopt(argc, argv, "s:d:x:p:q:P:t:b:m:whv?")) != -1) { @@ -235,24 +246,17 @@ int main(int argc, char **argv) exit(1); } - while (!quit) { + while (running) { FD_ZERO(&rdfs); FD_SET(s, &rdfs); FD_SET(t, &rdfs); - FD_SET(0, &rdfs); if ((ret = select(t+1, &rdfs, NULL, NULL, NULL)) < 0) { perror("select"); continue; } - if (FD_ISSET(0, &rdfs)) { - getchar(); - quit = 1; - printf("quit due to keyboard input.\n"); - } - if (FD_ISSET(s, &rdfs)) { nbytes = read(s, buffer, 4096); if (nbytes < 0) { -- 2.39.2