From 180eceff4d791c64654beff6e46b06a5e008f6c5 Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Mon, 20 Mar 2023 10:05:58 +0900 Subject: [PATCH] isotptun: 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. Signed-off-by: Yasushi SHOJI --- isotptun.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/isotptun.c b/isotptun.c index ee473fd..2a39ea7 100644 --- a/isotptun.c +++ b/isotptun.c @@ -79,6 +79,7 @@ #define BUF_LEN (MAX_PDU_LENGTH + 1) static volatile int running = 1; +static volatile sig_atomic_t signal_num; static void fake_syslog(int priority, const char *format, ...) { @@ -130,6 +131,7 @@ void print_usage(char *prg) void sigterm(int signo) { running = 0; + signal_num = signo; } int main(int argc, char **argv) @@ -403,5 +405,9 @@ int main(int argc, char **argv) close(s); close(t); + + if (signal_num) + return 128 + signal_num; + return EXIT_SUCCESS; }