From f45de1b782c08334c60e74945ce44b4f8503afa0 Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Mon, 20 Mar 2023 10:06:42 +0900 Subject: [PATCH] canlogserver: 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. canlogserver.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 --- canlogserver.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/canlogserver.c b/canlogserver.c index 51d548f..aa41347 100644 --- a/canlogserver.c +++ b/canlogserver.c @@ -84,6 +84,7 @@ static int max_devname_len; extern int optind, opterr, optopt; static volatile int running = 1; +static volatile sig_atomic_t signal_num; void print_usage(char *prg) { @@ -164,7 +165,8 @@ void childdied(int i) */ void shutdown_gra(int i) { - exit(0); + running = 0; + signal_num = i; } @@ -433,5 +435,9 @@ int main(int argc, char **argv) close(s[i]); close(accsocket); + + if (signal_num) + return 128 + signal_num; + return 0; }