Repository navigation
watchdog: disarm on any exit once the watchdog is armed - #58
Conversation
PR Summary by QodoDisarm the watchdog on process exit
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1.
|
watchdog_start() runs before sdk_start(), but several exits after that point never reach the watchdog_stop() at the end of main(): the HAL_ERROR returns for a failed sdk_start() and for empty RTSP credentials, and the exit() in handle_error() after a fatal signal. Each leaves the watchdog armed with nothing feeding it, so on a NOWAYOUT kernel a startup failure turns into a board reset. Register watchdog_stop() with atexit() as soon as the device is opened. watchdog_stop() already returns early when nothing is open, so the normal teardown call and the atexit call do not clash.
handle_error() runs as a signal handler for SIGSEGV, SIGBUS and the other fatal signals, but called exit(), which runs the atexit handlers and flushes stdio. That is not async-signal-safe, and with the watchdog now disarmed from atexit it means a crash could disarm the watchdog and then block on the stderr lock, leaving a hung process that nothing resets. Use _exit() so a crash skips the atexit handlers: the watchdog stays armed and the board recovers, while startup failures and normal exits still disarm it.
e753c33 to
ebdbcb9
Compare
|
Good catch from the review. Pushed a follow-up: handle_error() now leaves through _exit(), so a fatal signal skips the atexit handlers and stdio entirely. A crash keeps the watchdog armed and the board resets as before, while startup failures and normal exits still disarm it. Also rebased on master now that #56 and #57 are in. |
|
Awesome, kudos for finding that! |
watchdog_start() runs before sdk_start(), but several exits after that
point never reach the watchdog_stop() at the end of main(): the
HAL_ERROR returns for a failed sdk_start() and for empty RTSP
credentials, and the exit() in handle_error() after a fatal signal. Each
leaves the watchdog armed with nothing feeding it, so on a NOWAYOUT
kernel a startup failure turns into a board reset.
Register watchdog_stop() with atexit() as soon as the device is opened.
watchdog_stop() already returns early when nothing is open, so the
normal teardown call and the atexit call do not clash.
Built for infinity6e (SSC338Q). We've been running this fix on SSC338Q units.