Files
mesh-catalog/modules/restic/cmd/restic-backups/clock.go
T
jschoubben 7f05fad58a
mesh/merge-gate pass: builds restic → ace, g14, novox, shanks; no bus step; every machine composes with the change as it did without (4 of 4 compose)
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery delivered
restic: judge no night overdue where nothing is declared, and a count's age by the time the machine was awake
A machine that backs up nothing read as missing its night after 26 hours up, and a laptop's count, last
written before it slept, read as stale on waking until the next look (novox/hq issue 489).
2026-10-11 21:10:11 +02:00

31 lines
931 B
Go

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())
}