mirror of
https://github.com/linux-can/can-utils.git
synced 2026-08-05 06:20:00 +02:00
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.
This commit is contained in:
+13
-9
@@ -58,6 +58,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -70,6 +71,8 @@
|
|||||||
|
|
||||||
#define NO_CAN_ID 0xFFFFFFFFU
|
#define NO_CAN_ID 0xFFFFFFFFU
|
||||||
|
|
||||||
|
static volatile int running = 1;
|
||||||
|
|
||||||
void print_usage(char *prg)
|
void print_usage(char *prg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nUsage: %s [options] <CAN interface>\n\n", prg);
|
fprintf(stderr, "\nUsage: %s [options] <CAN interface>\n\n", prg);
|
||||||
@@ -93,6 +96,11 @@ void print_usage(char *prg)
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sigterm(int signo)
|
||||||
|
{
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
fd_set rdfs;
|
fd_set rdfs;
|
||||||
@@ -103,12 +111,15 @@ int main(int argc, char **argv)
|
|||||||
static struct can_isotp_fc_options fcopts;
|
static struct can_isotp_fc_options fcopts;
|
||||||
int opt, ret;
|
int opt, ret;
|
||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt;
|
||||||
static int quit;
|
|
||||||
static int verbose;
|
static int verbose;
|
||||||
|
|
||||||
unsigned char buffer[4096];
|
unsigned char buffer[4096];
|
||||||
int nbytes;
|
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;
|
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) {
|
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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!quit) {
|
while (running) {
|
||||||
|
|
||||||
FD_ZERO(&rdfs);
|
FD_ZERO(&rdfs);
|
||||||
FD_SET(s, &rdfs);
|
FD_SET(s, &rdfs);
|
||||||
FD_SET(t, &rdfs);
|
FD_SET(t, &rdfs);
|
||||||
FD_SET(0, &rdfs);
|
|
||||||
|
|
||||||
if ((ret = select(t+1, &rdfs, NULL, NULL, NULL)) < 0) {
|
if ((ret = select(t+1, &rdfs, NULL, NULL, NULL)) < 0) {
|
||||||
perror("select");
|
perror("select");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(0, &rdfs)) {
|
|
||||||
getchar();
|
|
||||||
quit = 1;
|
|
||||||
printf("quit due to keyboard input.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FD_ISSET(s, &rdfs)) {
|
if (FD_ISSET(s, &rdfs)) {
|
||||||
nbytes = read(s, buffer, 4096);
|
nbytes = read(s, buffer, 4096);
|
||||||
if (nbytes < 0) {
|
if (nbytes < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user