carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package hostexec
4
5import (
6 "golang.org/x/sys/unix"
7 "os"
8 "strings"
9 "time"
10)
11
12type SystemClock struct{}
13
14func (SystemClock) Now() (time.Time, int64, error) {
15 var ts unix.Timespec
16 if err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil {
17 return time.Time{}, 0, err
18 }
19 return time.Now(), ts.Nano(), nil
20}
21func (SystemClock) After(d time.Duration) <-chan time.Time { return time.After(d) }
22func BootID() (string, error) {
23 b, err := os.ReadFile("/proc/sys/kernel/random/boot_id")
24 if err != nil {
25 return "", err
26 }
27 id := strings.TrimSpace(string(b))
28 if !validID(id) {
29 return "", ErrState
30 }
31 return id, nil
32}
33