package main // The machine's monotonic clock, shared by its processes: the night's process writes it beside its count and // the health tool, in another process, reads it again (novox/hq issue 489). Go's own monotonic reading is // only comparable within one process. import ( "os" "strings" "syscall" "time" "unsafe" ) const bootID = "/proc/sys/kernel/random/boot_id" // machineClock is this boot's id and CLOCK_MONOTONIC, which on Linux does not run while the machine is // suspended and begins again at each boot; "" and 0 when either cannot be read. func machineClock() (string, time.Duration) { raw, err := os.ReadFile(bootID) if err != nil { return "", 0 } var ts syscall.Timespec const clockMonotonic = 1 if _, _, e := syscall.Syscall(syscall.SYS_CLOCK_GETTIME, clockMonotonic, uintptr(unsafe.Pointer(&ts)), 0); e != 0 { return "", 0 } return strings.TrimSpace(string(raw)), time.Duration(ts.Nano()) }