Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ void handle_error(int signo) {
sprintf(msg, "Error occured (%d)! Quitting...\n", signo);
write(STDERR_FILENO, msg, strlen(msg));
keepRunning = 0;
exit(EXIT_FAILURE);
/* _exit(), not exit(): from a signal handler only async-signal-safe
calls are allowed, and skipping the atexit handlers leaves the
watchdog armed so a crash still ends in a reset */
_exit(EXIT_FAILURE);
}

void handle_exit(int signo) {
Expand Down
6 changes: 6 additions & 0 deletions src/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ int watchdog_start(int timeout) {

ioctl(fd, WDIOC_SETTIMEOUT, &timeout);

/* Disarm on any normal exit from here on, including the error returns
out of main(), so a startup failure does not end in a reset. A fatal
signal leaves through _exit() in handle_error() and keeps it armed.
watchdog_stop() is safe to call twice. */
atexit(watchdog_stop);
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.

HAL_INFO("watchdog", "Watchdog started!\n");
return EXIT_SUCCESS;
}
Expand Down