From 74e0d28d1aaa3d8dab1a80f84ae0c5c5f2328406 Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Mon, 20 Mar 2023 10:04:56 +0900 Subject: [PATCH] cangen: 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 --- cangen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cangen.c b/cangen.c index bd88d9f..688a73a 100644 --- a/cangen.c +++ b/cangen.c @@ -91,6 +91,7 @@ extern int optind, opterr, optopt; static volatile int running = 1; +static volatile sig_atomic_t signal_num; static unsigned long long enobufs_count; static bool ignore_enobufs; static bool use_so_txtime; @@ -220,6 +221,7 @@ static void print_usage(char *prg) static void sigterm(int signo) { running = 0; + signal_num = signo; } static int setsockopt_txtime(int fd) @@ -887,5 +889,8 @@ int main(int argc, char **argv) close(s); + if (signal_num) + return 128 + signal_num; + return 0; }