Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchdog: always close fd on watchdog stop #1

Merged
merged 1 commit into from
Mar 30, 2024

Conversation

strpbrk
Copy link
Contributor

@strpbrk strpbrk commented May 1, 2023

Current behavior

The user may asks for procd watchdog handler to be stopped with or without disabling it, by specifying the magicclose flag.

  • If the flag is set, the watchdog will be disabled and the fd closed, allowing the user to take control over the watchdog.
  • If the flag is not set, the watchdog will not be disabled and the fd will not be closed.

Use-case

I would like to take over the watchdog and handle it with a script.

Problem

Stopping the handler with magicclose == true is not reliable. If the system fails before the user re-enables the watchdog, the system might hang without a proper reset.

Stopping the handler with magicclose == false doesn't help either. The procd will only stop refreshing the watchdog, but will leave the fd open. At least on Raspberry Pi, this prevents anyone else from opening the watchdog device, resulting in EBUSY.

The fix

With this patch, watchdog fd will always be closed, regardless of the magicclose flag, allowing for the described use-case. To take over the watchdog, stop it with magicclose == false and open the watchdog device in your custom way.

Peculiarity

You will note an allegedly critical log line coming from kernel "watchdog did not stop!" This is actually what we want. In my opinion, it should only be a warning, not a critical message.

Backward compatibility

For user that previously stopped the watchdog handler with magicclose == true, the functionality remains unchanged.

@aparcar
Copy link
Member

aparcar commented Oct 26, 2023

CC @dangowrt

The user may asks for procd watchdog handler to be stopped
with or without disabling it, by specifying the magicclose flag.
If the flag is set, the watchdog will be disabled and the fd closed,
allowing the user to take control over the watchdog.

There is a race in this scenario. If the system fails before
the user re-enables the watchdog, the system might hang
without a proper reset.

To prevent this, the user should ask the procd handler to be stopped
without disabling the watchdog, by specifying magicclose as false.
However, in this case, the procd will only stop refreshing the watchdog,
but will leave the fd open. At least on Raspberry Pi, this prevents
anyone else from opening the watchdog device, resulting in EBUSY.

With this patch, watchdog fd will always be closed, regardless
of the magicclose flag, allowing for the described safe use-case.

For user that previously stopped the watchdog handler
with the magicclose flag, the functionality remains unchanged.

Signed-off-by: Dragan Milenkovic <[email protected]>
@openwrt-bot openwrt-bot merged commit 254810d into openwrt:master Mar 30, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants