diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-05-13 07:44:50 -0700 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-05-15 21:55:19 +0800 |
commit | f81048f8f5058e86b1c54e39eb59a1ac7ee3bd4b (patch) | |
tree | 8db0e059f8da6b64886d29f919625805af9de44a /src | |
parent | 4340e5b6df241e4883a1e58dc3446ea489a388a9 (diff) | |
download | systemd-f81048f8f5058e86b1c54e39eb59a1ac7ee3bd4b.tar.gz |
watchdog: always disarm watchdog properly before closing it
If we change the watchdog device we should disarm the old one first.
Similar, if we open the watchdog, but then fail setting it up, disarm it
before closing it again.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/watchdog.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index 4445efb125..4c1a968718 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -318,9 +318,10 @@ static int open_watchdog(void) { STRV_FOREACH(wd, try_order) { watchdog_fd = open(*wd, O_WRONLY|O_CLOEXEC); if (watchdog_fd >= 0) { - r = free_and_strdup(&watchdog_device, *wd); - if (r < 0) - return log_oom_debug(); + if (free_and_strdup(&watchdog_device, *wd) < 0) { + r = log_oom_debug(); + goto close_and_fail; + } break; } @@ -342,8 +343,12 @@ static int open_watchdog(void) { r = update_timeout(); if (r < 0) - watchdog_close(true); + goto close_and_fail; + + return 0; +close_and_fail: + watchdog_close(/* disarm= */ true); return r; } @@ -356,7 +361,7 @@ int watchdog_set_device(const char *path) { r = free_and_strdup(&watchdog_device, path); if (r > 0) /* watchdog_device changed */ - watchdog_fd = safe_close(watchdog_fd); + watchdog_close(/* disarm= */ true); return r; } |