示例#1
0
 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))
示例#2
0
 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))
示例#3
0
    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)
示例#4
0
 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
示例#5
0
    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)
示例#6
0
 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))
示例#7
0
 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
示例#8
0
 def keepalive(self):
     try:
         os.write(self._fd, b'1')
     except OSError as e:
         raise WatchdogError(
             "Could not send watchdog keepalive: {0}".format(e))
示例#9
0
 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))