Pulse/internal/hostmetrics/arc_freebsd.go
rcourtman 6c720b7aea fix(freebsd): use golang.org/x/sys/unix.SysctlRaw instead of syscall.SysctlRaw
syscall.SysctlRaw is Darwin-only in Go's standard library; FreeBSD
requires the equivalent from golang.org/x/sys/unix. This fixes the
Docker cross-compilation build failure for the freebsd/amd64 target.

(cherry picked from commit 5fe16c75a075b817f90b7192d8270a7bd6677017)
2026-02-18 13:00:02 +00:00

29 lines
638 B
Go

//go:build freebsd
package hostmetrics
import (
"encoding/binary"
"fmt"
"golang.org/x/sys/unix"
)
func readFreeBSDARCSize() (uint64, error) {
// kstat.zfs.misc.arcstats.size holds the current ARC size in bytes.
// This is a uint64 sysctl on FreeBSD.
raw, err := unix.SysctlRaw("kstat.zfs.misc.arcstats.size")
if err != nil {
return 0, err
}
switch len(raw) {
case 8:
return binary.NativeEndian.Uint64(raw), nil
case 4:
// Defensive: some environments may expose a 32-bit value.
return uint64(binary.NativeEndian.Uint32(raw)), nil
default:
return 0, fmt.Errorf("unexpected sysctl value size: %d", len(raw))
}
}