canbusload: 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. canbusload.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
parent
180eceff4d
commit
16a717c81e
10
canbusload.c
10
canbusload.c
|
|
@ -82,6 +82,8 @@ static struct {
|
|||
unsigned int recv_bits_dbitrate;
|
||||
} stat[MAXSOCK+1];
|
||||
|
||||
static volatile int running = 1;
|
||||
static volatile sig_atomic_t signal_num;
|
||||
static int max_devname_len; /* to prevent frazzled device name output */
|
||||
static int max_bitrate_len;
|
||||
static int currmax;
|
||||
|
|
@ -124,7 +126,8 @@ void print_usage(char *prg)
|
|||
|
||||
void sigterm(int signo)
|
||||
{
|
||||
exit(0);
|
||||
running = 0;
|
||||
signal_num = signo;
|
||||
}
|
||||
|
||||
void printstats(int signo)
|
||||
|
|
@ -382,7 +385,7 @@ int main(int argc, char **argv)
|
|||
if (redraw)
|
||||
printf("%s", CLR_SCREEN);
|
||||
|
||||
while (1) {
|
||||
while (running) {
|
||||
|
||||
FD_ZERO(&rdfs);
|
||||
for (i=0; i<currmax; i++)
|
||||
|
|
@ -425,5 +428,8 @@ int main(int argc, char **argv)
|
|||
for (i=0; i<currmax; i++)
|
||||
close(s[i]);
|
||||
|
||||
if (signal_num)
|
||||
return 128 + signal_num;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue