Skip to content

Introduce pkg/watchdog to detect hardware watchdogs#468

Merged
jaypipes merged 1 commit into
jaypipes:mainfrom
europaul:add-watchdog
Jul 8, 2026
Merged

Introduce pkg/watchdog to detect hardware watchdogs#468
jaypipes merged 1 commit into
jaypipes:mainfrom
europaul:add-watchdog

Conversation

@europaul

@europaul europaul commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Adds a new pkg/watchdog package that reports whether the host system has a hardware
watchdog:

  • WatchdogInfo.Present is true when /sys/class/watchdog has at least one entry, or —
    for kernels predating the watchdog sysfs class (< 4.5) — when the /dev/watchdog
    character device exists.
  • Lookup paths are routed through linuxpath; this adds a Dev path root alongside the
    existing ones, with a corresponding "/dev" key for WithPathOverrides.
  • /sys/class/watchdog/* is added to the snapshot clone content, so detection also works
    against ghw snapshots.
  • Wired into HostInfo, the ghw package aliases (ghw.Watchdog(), ghw.WatchdogInfo),
    a new ghwc watchdog command (including the default human-format output), and the README.

Testing

  • New chroot-based unit tests cover detection via the sysfs class, via the /dev/watchdog
    fallback, and the absent case.
  • go build ./... && go vet ./... && go test ./... pass on Linux; cross-compiles for
    windows/darwin.
  • Verified end-to-end on a real machine: ghwc watchdog prints watchdog present: true,
    and a snapshot round-trip (snapshot.CloneTreeIntoghw.Watchdog(ghw.WithChroot(dir)))
    detects it from the cloned tree as well.

Add a new watchdog package that reports whether the host system has a
hardware watchdog, detected via a non-empty /sys/class/watchdog class
directory or, on kernels predating the watchdog sysfs class (< 4.5),
the /dev/watchdog character device.

The lookup paths are routed through linuxpath, adding a Dev path root
(with a "/dev" path override key) alongside the existing roots. The
watchdog class directory is added to the snapshot clone content so
detection works against ghw snapshots. WatchdogInfo is wired into
HostInfo, the ghw package aliases, and a new `ghwc watchdog` command.

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@jaypipes jaypipes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@europaul this is brilliant, mate. can't find anything at all wrong with it. awesome work :)

@jaypipes jaypipes merged commit cfcf423 into jaypipes:main Jul 8, 2026
15 checks passed
@europaul

europaul commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@europaul this is brilliant, mate. can't find anything at all wrong with it. awesome work :)

thank you! I've got some more PRs from our fork https://github.com/zededa/ghw. Is it okay if I keep them coming at the same pace?

@jaypipes

jaypipes commented Jul 9, 2026

Copy link
Copy Markdown
Owner

@europaul this is brilliant, mate. can't find anything at all wrong with it. awesome work :)

thank you! I've got some more PRs from our fork https://github.com/zededa/ghw. Is it okay if I keep them coming at the same pace?

@europaul Keep 'em coming! I'm loving it! :)

@jaypipes

jaypipes commented Jul 9, 2026

Copy link
Copy Markdown
Owner

@europaul BTW, if you'd like a higher-bandwidth conversation, you can find me on Kubernetes slack community with the same username...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants