Skip to content

Commit

Permalink
canlogserver: Follow Bash exit status when signaled
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yashi committed Mar 20, 2023
1 parent 16a717c commit f45de1b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion canlogserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static int max_devname_len;
extern int optind, opterr, optopt;

static volatile int running = 1;
static volatile sig_atomic_t signal_num;

void print_usage(char *prg)
{
Expand Down Expand Up @@ -164,7 +165,8 @@ void childdied(int i)
*/
void shutdown_gra(int i)
{
exit(0);
running = 0;
signal_num = i;
}


Expand Down Expand Up @@ -433,5 +435,9 @@ int main(int argc, char **argv)
close(s[i]);

close(accsocket);

if (signal_num)
return 128 + signal_num;

return 0;
}

0 comments on commit f45de1b

Please sign in to comment.