From 16a717c81e2d30f83bfda2c6e785260f255f074f Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Mon, 20 Mar 2023 09:58:29 +0900 Subject: [PATCH] canbusload: Follow Bash exit status when signaled Bash and many other shells use 128 + signum as the exit status when a program get signal and exit. Follow the common behavior so that we know how the programs are killed. canbusload.c was using a non-safe function, exit(3), in the signal handler. This commit replaces it with the way other programs in can-utils are using; set running = 0 to exit from the while loop. Signed-off-by: Yasushi SHOJI --- canbusload.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/canbusload.c b/canbusload.c index 47b62fd..83a6c80 100644 --- a/canbusload.c +++ b/canbusload.c @@ -82,6 +82,8 @@ static struct { unsigned int recv_bits_dbitrate; } stat[MAXSOCK+1]; +static volatile int running = 1; +static volatile sig_atomic_t signal_num; static int max_devname_len; /* to prevent frazzled device name output */ static int max_bitrate_len; static int currmax; @@ -124,7 +126,8 @@ void print_usage(char *prg) void sigterm(int signo) { - exit(0); + running = 0; + signal_num = signo; } void printstats(int signo) @@ -382,7 +385,7 @@ int main(int argc, char **argv) if (redraw) printf("%s", CLR_SCREEN); - while (1) { + while (running) { FD_ZERO(&rdfs); for (i=0; i