WATCHDOG(4)
ππ WATCHDOG β kernel interfaces manual ππ
okay so bestie, buckle up, this is the watchdog(4) page from the kernel interfaces manual and it's genuinely so good. no cap.
β¨ NAME β¨
watchdog β hardware and software watchdog πΆ
π SYNOPSIS π
#include <sys/watchdog.h>
π¦ DESCRIPTION π¦
So the watchdog facility is literally what you use to control hardware and software watchdogs. It's giving "someone please notice if I stop responding" energy and honestly? iconic.
The device /dev/fido supports several optional ioctl(2) calls for configuration, and it responds to a single operational ioctl call, WDIOCPATPAT. That one takes a single argument which represents a timeout value β specified as a power of two nanoseconds β or-ed with a flag that selects active or passive control of the watchdog.
WD_ACTIVEβ says the watchdog will be kept from timing out from userland, for instance by thewatchdogd(8)daemon. πWD_PASSIVEβ says the watchdog will be kept from timing out from the kernel.
The WDIOCPATPAT ioctl(2) call will return success if just one of the available watchdog(9) implementations supports setting the timeout to the specified timeout. That means at least one watchdog is armed. π«‘ By default, this will be a hardware watchdog if one is present, but if no hardware watchdog is able to process the request, a default software watchdog is enabled. And if the call fails β for instance if none of the watchdog(9) implementations support the timeout length β then all watchdogs are disabled and must be explicitly re-enabled. π
To disable the watchdogs pass WD_TO_NEVER. If disarming the watchdog(s) failed, an error is returned. The watchdog might still be armed! π
π§ the optional configuration ioctls π§
Here they are, listed with the type of the parameter each one uses. Examples of their use can be found in watchdogd(8).
WDIOC_SETTIMEOUTint β set/reset the timer β°WDIOC_GETTIMEOUTint β get total timeoutWDIOC_GETTIMELEFTint β get time leftWDIOC_GETPRETIMEOUTint β get the pre-timeoutWDIOC_SETPRETIMEOUTint β set the pre-timeoutWDIOC_SETPRETIMEOUTACTint β Set the action when a pre-timeout occurs (seeWD_SOFT_*below).WDIOC_SETSOFTint β Use an internal software watchdog instead of hardware. There is also an external software watchdog, which is used by default if no hardware watchdog was attached.WDIOC_SETSOFTTIMEOUTACTint β Set the action whan a soft timeout occurs. (yes bestie, "whan". we love her. we're not fixing her. π )
πΈ the actions πΈ
The actions that may be specified for the pre-timeout or the internal software watchdog are listed here. Multiple actions can be specified by ORing values together.
WD_SOFT_PANICβ panic π±WD_SOFT_DDBβ enter debugger πWD_SOFT_LOGβlog(9)WD_SOFT_PRINTβprintf(9)
π RETURN VALUES π
The WDIOCPATPAT ioctl returns zero on success and non-zero on failure.
[EOPNOTSUPP]β No watchdog present in the kernel, or none of the watchdogs supports the requested timeout value (timeout value other than 0).[EOPNOTSUPP]β Watchdog could not be disabled (timeout value of 0).[EINVAL]β Invalid flag combination passed.
The configuration ioctl operations return zero on success and non-zero on failure. β¨
π₯ EXAMPLES π₯
#include <paths.h>
#include <sys/watchdog.h>
#define WDPATH "/dev/" _PATH_WATCHDOG
int wdfd = -1;
static void
wd_init(void)
{
wdfd = open(WDPATH, O_RDWR);
if (wdfd == -1)
err(1, WDPATH);
}
static void
wd_reset(u_int timeout)
{
if (ioctl(wdfd, WDIOCPATPAT, &timeout) == -1)
err(1, "WDIOCPATPAT");
}
/* in main() */
wd_init();
wd_reset(WD_ACTIVE|WD_TO_8SEC);
/* potential freeze point */
wd_reset(WD_TO_NEVER);
Enables a watchdog to recover from a potentially freezing piece of code. π§β‘οΈπ₯
And then this, in your kernel config:
options SW_WATCHDOG
forces a software watchdog in the kernel to be configured even if a hardware watchdog is configured, dropping to KDB or panicking when firing, depending on the KDB and KDB_UNATTENDED kernel configuration options. π
π SEE ALSO π
β HISTORY β
The watchdog code first appeared in FreeBSD 5.1. a whole era. π«Ά
π AUTHORS π
The watchdog facility was written by Poul-Henning Kamp <phk@FreeBSD.org>. The software watchdog code and this manual page were written by Sean Kelly <smkelly@FreeBSD.org>. Some contributions were made by Jeff Roberson <jeff@FreeBSD.org>. legends only, honestly.
π BUGS π
The WD_PASSIVE option has not yet been implemented. it's giving "coming soon" but make it 2003. π
okay that's the whole page bestie, you ate it. this is from the Debian build, dated January 2, 2018 β go forth and arm your watchdogs, ily, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2004 Poul-Henning Kamp <phk@FreeBSD.org>
- Copyright (c) 2003, 2004 Sean M. Kelly <smkelly@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms