]> rtime.felk.cvut.cz Git - sojka/can-utils.git/commitdiff
Remove feature to quit the isotptun by keypress (from stdin) as it was not possible...
authorOliver Hartkopp <socketcan@hartkopp.net>
Wed, 25 Nov 2009 16:43:17 +0000 (16:43 +0000)
committerOliver Hartkopp <socketcan@hartkopp.net>
Wed, 25 Nov 2009 16:43:17 +0000 (16:43 +0000)
Added a signal handler to gracefully leave the isotptun.

isotptun.c

index d40df87cb88e662697be8f19ba721f409e1f6763..1ea56b9831fac2fb2df2a13d6c71533e2ece76cc 100644 (file)
@@ -58,6 +58,7 @@
 #include <string.h>
 #include <libgen.h>
 #include <errno.h>
+#include <signal.h>
 
 #include <net/if.h>
 #include <sys/types.h>
@@ -70,6 +71,8 @@
 
 #define NO_CAN_ID 0xFFFFFFFFU
 
+static volatile int running = 1;
+
 void print_usage(char *prg)
 {
        fprintf(stderr, "\nUsage: %s [options] <CAN interface>\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) {