slcand: 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.

slcand was returning 0 when SIGINT and SIGTERM is received.  This
commit, instead, return 128 + signum when it gets a signal.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
pull/416/head
Yasushi SHOJI 2023-03-20 10:14:03 +09:00
parent 7490986650
commit 69ded0fbad
1 changed files with 4 additions and 8 deletions

View File

@ -93,7 +93,7 @@ void print_usage(char *prg)
}
static int slcand_running;
static int exit_code;
static volatile sig_atomic_t exit_code;
static char ttypath[TTYPATH_LENGTH];
static void child_handler(int signum)
@ -104,16 +104,12 @@ static void child_handler(int signum)
/* exit parent */
exit(EXIT_SUCCESS);
break;
case SIGINT:
case SIGTERM:
case SIGALRM:
case SIGCHLD:
syslogger(LOG_NOTICE, "received signal %i on %s", signum, ttypath);
exit_code = EXIT_FAILURE;
slcand_running = 0;
break;
case SIGINT:
case SIGTERM:
syslogger(LOG_NOTICE, "received signal %i on %s", signum, ttypath);
exit_code = EXIT_SUCCESS;
exit_code = 128 + signum;
slcand_running = 0;
break;
}