def set_timeout(self, timeout): timeout = int(timeout) if not 0 < timeout < 0xFFFF: raise WatchdogError( "Invalid timeout {0}. Supported values are between 1 and 65535" .format(timeout)) try: self._ioctl(WDIOC_SETTIMEOUT, ctypes.c_int(timeout)) except (WatchdogError, OSError, IOError) as e: raise WatchdogError( "Could not set timeout on watchdog device: {}".format(e))
def set_timeout(self, timeout): timeout = int(timeout) if not 0 < timeout < 0xFFFF: raise WatchdogError( "Invalid timeout {0}. Supported values are between 1 and 65535" .format(timeout)) self._ioctl(WDIOC_SETTIMEOUT, ctypes.c_int(timeout))
def _ioctl(self, func, arg, mutate_arg=False): if self._fd is None: raise WatchdogError("Watchdog device is closed") result = fcntl.ioctl(self._fd, func, arg, mutate_arg) if result < 0: raise IOError(result)
def get_timeout(self): timeout = ctypes.c_int() try: self._ioctl(WDIOC_GETTIMEOUT, timeout) except (WatchdogError, OSError, IOError) as e: raise WatchdogError( "Could not get timeout on watchdog device: {}".format(e)) return timeout.value
def _ioctl(self, func, arg): """Runs the specified ioctl on the underlying fd. Raises WatchdogError if the device is closed. Raises OSError or IOError (Python 2) when the ioctl fails.""" if self._fd is None: raise WatchdogError("Watchdog device is closed") fcntl.ioctl(self._fd, func, arg, True)
def close(self): if self.is_running: try: os.write(self._fd, b'V') os.close(self._fd) self._fd = None except OSError as e: raise WatchdogError("Error while closing {0}: {1}".format( self.describe(), e))
def get_support(self): if self._support_cache is None: info = watchdog_info() try: self._ioctl(WDIOC_GETSUPPORT, info) except (WatchdogError, OSError, IOError) as e: raise WatchdogError( "Could not get information about watchdog device: {}". format(e)) self._support_cache = WatchdogInfo( info.options, info.firmware_version, bytearray( info.identity).decode(errors='ignore').rstrip('\x00')) return self._support_cache
def keepalive(self): try: os.write(self._fd, b'1') except OSError as e: raise WatchdogError( "Could not send watchdog keepalive: {0}".format(e))
def open(self): try: self._fd = os.open(self.device, os.O_WRONLY) except OSError as e: raise WatchdogError("Can't open watchdog device: {0}".format(e))