Skip to content

Commit bbb0e41

Browse files
committed
Introduce atomic signal handler variables for enhanced safety
1 parent 819f430 commit bbb0e41

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/main.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ extern int opterr, optind;
140140
#define OPTSTR "i:v:t:h"
141141
#define USAGE_FMT "%s -i <file.ini> [-v] [-h] [-t testname]\n"
142142

143-
static volatile int kill_error = 10; // after 10 times SIGUSR1 the app exits forcefully
144-
static volatile bool main_alive = true; // terminate application
145-
static volatile int return_code = EXIT_NORMALLY;
143+
static volatile sig_atomic_t kill_error = 10; // after 10 times SIGUSR1 the app exits forcefully
144+
static volatile sig_atomic_t main_alive = 1; // terminate application (1=true, 0=false)
145+
static volatile sig_atomic_t return_code = EXIT_NORMALLY;
146146

147147
// send signal INT to restart application
148148
void SIGINT_handler(int sig)
149149
{
150150
UNUSED(sig);
151151
LOGN("INT detected, Restarting");
152-
main_alive = false;
152+
main_alive = 0;
153153
return_code = EXIT_RESTART;
154154
}
155155

@@ -158,7 +158,7 @@ void SIGQUIT_handler(int sig)
158158
{
159159
UNUSED(sig);
160160
LOGN("QUIT detected, Rebooting");
161-
main_alive = false;
161+
main_alive = 0;
162162
return_code = EXIT_REBOOT;
163163
}
164164

@@ -167,7 +167,7 @@ void SIGUSR1_handler(int sig)
167167
{
168168
UNUSED(sig);
169169
LOGN("USR1 detected, Terminating");
170-
main_alive = false;
170+
main_alive = 0;
171171
return_code = EXIT_NORMALLY;
172172

173173
if(kill_error > 0)
@@ -331,7 +331,7 @@ int main(int argc, char *argv[])
331331
if(main_alive)
332332
{
333333
LOGE("UDP poll failed");
334-
main_alive = false;
334+
main_alive = 0;
335335
continue;
336336
}
337337
}
@@ -408,19 +408,19 @@ int main(int argc, char *argv[])
408408
if(filecmd_exists(FILECMD_STOPAPP))
409409
{
410410
LOGN("%s has stopped by file command", APPNAME);
411-
main_alive = false;
411+
main_alive = 0;
412412
return_code = EXIT_NORMALLY;
413413
}
414414
else if(filecmd_exists(FILECMD_RESTARTAPP))
415415
{
416416
LOGN("%s has restarted by file command", APPNAME);
417-
main_alive = false;
417+
main_alive = 0;
418418
return_code = EXIT_RESTART;
419419
}
420420
else if(filecmd_exists(FILECMD_REBOOT))
421421
{
422422
LOGN("System reboot by file command");
423-
main_alive = false;
423+
main_alive = 0;
424424
return_code = EXIT_REBOOT;
425425
}
426426

@@ -437,7 +437,7 @@ int main(int argc, char *argv[])
437437
if(tm_now->tm_hour == apps_get_state()->reboot_params.daily_time.hour && tm_now->tm_min == apps_get_state()->reboot_params.daily_time.min)
438438
{
439439
LOGN("Periodic reboot triggered (daily time)");
440-
main_alive = false;
440+
main_alive = 0;
441441
return_code = EXIT_REBOOT;
442442
}
443443

@@ -451,7 +451,7 @@ int main(int argc, char *argv[])
451451
if(uptime_minutes > 0 && uptime_minutes % apps_get_state()->reboot_params.interval_minutes == 0)
452452
{
453453
LOGN("Periodic reboot triggered (interval)");
454-
main_alive = false;
454+
main_alive = 0;
455455
return_code = EXIT_REBOOT;
456456
}
457457

0 commit comments

Comments
 (0)