diff options
author | Maxim Devaev <[email protected]> | 2021-09-26 09:31:54 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2021-09-26 09:31:54 +0300 |
commit | 51ed5384154474a624311913f5aba91ff10662ea (patch) | |
tree | 87b31d022ab855debae10ce4a2e58f6a6db1b373 /kvmd | |
parent | 2a0ed6a92cbf1ed0ae1d8e31e4b6d7fb5b1ebf8c (diff) |
renamed device to rtc
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/watchdog/__init__.py | 30 |
2 files changed, 16 insertions, 16 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index b516d98d..ca9bf374 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -694,7 +694,7 @@ def _get_config_scheme() -> Dict: }, "watchdog": { - "device": Option(0, type=valid_int_f0), + "rtc": Option(0, type=valid_int_f0), "timeout": Option(300, type=valid_int_f1), "interval": Option(30, type=valid_int_f1), }, diff --git a/kvmd/apps/watchdog/__init__.py b/kvmd/apps/watchdog/__init__.py index 0caa39a6..a21ca72c 100644 --- a/kvmd/apps/watchdog/__init__.py +++ b/kvmd/apps/watchdog/__init__.py @@ -42,27 +42,27 @@ class RtcIsNotAvailableError(Exception): # ===== -def _join_rtc(device: int, key: str) -> str: - return f"{env.SYSFS_PREFIX}/sys/class/rtc/rtc{device}/{key}" +def _join_rtc(rtc: int, key: str) -> str: + return f"{env.SYSFS_PREFIX}/sys/class/rtc/rtc{rtc}/{key}" -def _read_int(device: int, key: str) -> int: - with open(_join_rtc(device, key)) as value_file: +def _read_int(rtc: int, key: str) -> int: + with open(_join_rtc(rtc, key)) as value_file: return int(value_file.read().strip() or "0") -def _write_int(device: int, key: str, value: int) -> None: - with open(_join_rtc(device, key), "w") as value_file: +def _write_int(rtc: int, key: str, value: int) -> None: + with open(_join_rtc(rtc, key), "w") as value_file: value_file.write(str(value)) -def _reset_alarm(device: int, timeout: int) -> None: - now = _read_int(device, "since_epoch") +def _reset_alarm(rtc: int, timeout: int) -> None: + now = _read_int(rtc, "since_epoch") if now == 0: raise RtcIsNotAvailableError("Current UNIX time == 0") try: for wake in [0, now + timeout]: - _write_int(device, "wakealarm", wake) + _write_int(rtc, "wakealarm", wake) except OSError as err: if err.errno != errno.EIO: raise @@ -72,30 +72,30 @@ def _reset_alarm(device: int, timeout: int) -> None: # ===== def _cmd_run(config: Section) -> None: logger = get_logger(0) - logger.info("Running watchdog loop on RTC%d ...", config.device) + logger.info("Running watchdog loop on RTC%d ...", config.rtc) fail = False try: while True: try: - _reset_alarm(config.device, config.timeout) + _reset_alarm(config.rtc, config.timeout) except RtcIsNotAvailableError as err: if not fail: - logger.error("RTC%d is not available now: %s; waiting ...", config.device, err) + logger.error("RTC%d is not available now: %s; waiting ...", config.rtc, err) fail = True else: if fail: - logger.info("RTC%d is available, working ...", config.device) + logger.info("RTC%d is available, working ...", config.rtc) fail = False time.sleep(config.interval) except (SystemExit, KeyboardInterrupt): if not fail: - _reset_alarm(config.device, config.timeout) + _reset_alarm(config.rtc, config.timeout) logger.info("The watchdog remains alarmed. Use 'kvmd-watchdog cancel' to disarm it") logger.info("Bye-bye") def _cmd_cancel(config: Section) -> None: - _write_int(config.device, "wakealarm", 0) + _write_int(config.rtc, "wakealarm", 0) # ===== |