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 <yashi@spacecubics.com>
pull/416/head
Yasushi SHOJI 2023-03-20 10:06:42 +09:00
parent 16a717c81e
commit f45de1b782
1 changed files with 7 additions and 1 deletions

View File

@ -84,6 +84,7 @@ static int max_devname_len;
extern int optind, opterr, optopt; extern int optind, opterr, optopt;
static volatile int running = 1; static volatile int running = 1;
static volatile sig_atomic_t signal_num;
void print_usage(char *prg) void print_usage(char *prg)
{ {
@ -164,7 +165,8 @@ void childdied(int i)
*/ */
void shutdown_gra(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(s[i]);
close(accsocket); close(accsocket);
if (signal_num)
return 128 + signal_num;
return 0; return 0;
} }