watchdog

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: BSD-3-Clause Imports: 5 Imported by: 3

Documentation

Overview

Package watchdog provides functions for interacting with the Linux watchdog.

The basic usage is:

wd, err := watchdog.Open(watchdog.Dev)
while running {
    wd.KeepAlive()
}
wd.MagicClose()

Open() arms the watchdog. MagicClose() disarms the watchdog.

Note not every watchdog driver supports every function!

For more, see: https://www.kernel.org/doc/Documentation/watchdog/watchdog-api.txt

Index

Constants

View Source
const Dev = "/dev/watchdog"

Dev is the name of the first watchdog. If there are multiple watchdogs, they are named /dev/watchdog0, /dev/watchdog1, ...

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option int32

Option are options passed to SetOptions().

const (
	// Unknown status error
	OptionUnknown Option = -1
	// Turn off the watchdog timer
	OptionDisableCard Option = 0x0001
	// Turn on the watchdog timer
	OptionEnableCard Option = 0x0002
	// Kernel panic on temperature trip
	OptionTempPanic Option = 0x0004
)

Bitset of possible flags for the Option type.

type Status

type Status int32

Status contains flags returned by Status() and BootStatus(). These are the same flags used for Support()'s options field.

const (
	// Unknown flag error
	StatusUnknown Status = -1
	// Reset due to CPU overheat
	StatusOverheat Status = 0x0001
	// Fan failed
	StatusFanFault Status = 0x0002
	// External relay 1
	StatusExtern1 Status = 0x0004
	// ExStatusl relay 2
	StatusExtern2 Status = 0x0008
	// Power bad/power fault
	StatusPowerUnder Status = 0x0010
	// Card previously reset the CPU
	StatusCardReset Status = 0x0020
	// Power over voltage
	StatusPowerOver Status = 0x0040
	// Set timeout (in seconds)
	StatusSetTimeout Status = 0x0080
	// Supports magic close char
	StatusMagicClose Status = 0x0100
	// Pretimeout (in seconds), get/set
	StatusPreTimeout Status = 0x0200
	// Watchdog triggers a management or other external alarm not a reboot
	StatusAlarmOnly Status = 0x0400
	// Keep alive ping reply
	StatusKeepAlivePing Status = 0x8000
)

Bitset of possible flags for the Status() type.

type Watchdog

type Watchdog struct {
	// contains filtered or unexported fields
}

Watchdog holds the descriptor of an open watchdog driver.

func Open

func Open(dev string) (*Watchdog, error)

Open arms the watchdog.

func (*Watchdog) BootStatus

func (w *Watchdog) BootStatus() (Status, error)

BootStatus returns the status at the last reboot.

func (*Watchdog) Close

func (w *Watchdog) Close() error

Close closes the device without disarming the watchdog.

func (*Watchdog) KeepAlive

func (w *Watchdog) KeepAlive() error

KeepAlive pets the watchdog.

func (*Watchdog) MagicClose

func (w *Watchdog) MagicClose() error

MagicClose disarms the watchdog. However if the kernel is compiled with CONFIG_WATCHDOG_NOWAYOUT=y, there may be no way to disarm the watchdog.

func (*Watchdog) PreTimeout

func (w *Watchdog) PreTimeout() (time.Duration, error)

PreTimeout returns the current watchdog pretimeout.

func (*Watchdog) SetOptions

func (w *Watchdog) SetOptions(options Option) error

SetOptions can be used to control some aspects of the cards operation.

func (*Watchdog) SetPreTimeout

func (w *Watchdog) SetPreTimeout(timeout time.Duration) error

SetPreTimeout sets the watchdog pretimeout on the fly. The pretimeout is the duration before triggering the preaction (such as an NMI, interrupt, ...). timeout must be a multiple of seconds; otherwise, an error is returned.

func (*Watchdog) SetTimeout

func (w *Watchdog) SetTimeout(timeout time.Duration) error

SetTimeout sets the watchdog timeout on the fly. It returns an error if the timeout gets set to the wrong value. timeout must be a multiple of seconds; otherwise, an error is returned.

func (*Watchdog) Status

func (w *Watchdog) Status() (Status, error)

Status returns the current status.

func (*Watchdog) Support

func (w *Watchdog) Support() (*unix.WatchdogInfo, error)

Support returns the WatchdogInfo struct.

func (*Watchdog) TimeLeft

func (w *Watchdog) TimeLeft() (time.Duration, error)

TimeLeft returns the duration before the reboot (to the nearest second).

func (*Watchdog) Timeout

func (w *Watchdog) Timeout() (time.Duration, error)

Timeout returns the current watchdog timeout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL