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
Merged
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
11 changes: 6 additions & 5 deletions watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ static int watchdog_open(bool cloexec)
return wdt_fd;
}

static void watchdog_close(void)
static void watchdog_close(bool with_release)
{
if (wdt_fd < 0)
return;

if (write(wdt_fd, "V", 1) < 0)
ERROR("WDT failed to write release: %m\n");
if (with_release) {
if (write(wdt_fd, "V", 1) < 0)
ERROR("WDT failed to write release: %m\n");
}

if (close(wdt_fd) == -1)
ERROR("WDT failed to close watchdog: %m\n");
Expand Down Expand Up @@ -137,8 +139,7 @@ void watchdog_set_stopped(bool val)
if (val) {
uloop_timeout_cancel(&wdt_timeout);

if (wdt_magicclose)
watchdog_close();
watchdog_close(wdt_magicclose);
}
else {
watchdog_open(true);
Expand Down
Loading