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

For j1939acd.c, it was using s.sig_term as a boolean key to exit from
the while loop.  This commit replaces a.sig_term with a.signal_num,
which holds the signal it received.

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

View File

@ -110,7 +110,7 @@ static struct {
uint64_t name;
uint8_t current_sa;
uint8_t last_sa;
int sig_term;
volatile sig_atomic_t signal_num;
int sig_alrm;
int sig_usr1;
int state;
@ -337,7 +337,7 @@ static void sighandler(int sig, siginfo_t *info, void *vp)
switch (sig) {
case SIGINT:
case SIGTERM:
s.sig_term = 1;
s.signal_num = sig;
break;
case SIGALRM:
s.sig_alrm = 1;
@ -531,7 +531,7 @@ int main(int argc, char *argv[])
install_signal(SIGUSR1);
install_signal(SIGUSR2);
while (!s.sig_term) {
while (!s.signal_num) {
if (s.sig_usr1) {
s.sig_usr1 = 0;
dump_status();
@ -648,6 +648,9 @@ done:
fprintf(stderr, "- shutdown\n");
claim_address(sock, s.name, J1939_IDLE_ADDR);
save_cache();
if (s.signal_num)
return 128 + s.signal_num;
return 0;
}