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 host
4
5import (
6 "io"
7 "os"
8
9 "github.com/carlosframework/platform/internal/hostbox"
10)
11
12func servingParkBootID() (string, error) {
13 f, err := os.Open("/proc/sys/kernel/random/boot_id")
14 if err != nil {
15 return "", err
16 }
17 defer f.Close()
18 b, err := io.ReadAll(io.LimitReader(f, 38))
19 if err != nil || len(b) != 37 || b[36] != '\n' {
20 return "", hostbox.ErrChanged
21 }
22 return string(b[:36]), nil
23}
24
25func (f *servingParkFS) currentBoot() (string, error) {
26 if f == nil || f.boot == nil {
27 return "", hostbox.ErrUnsupported
28 }
29 id, err := f.boot()
30 if err != nil {
31 return "", err
32 }
33 if !validServingParkBootID(id) {
34 return "", hostbox.ErrChanged
35 }
36 return id, nil
37}
38
39// A mount number is meaningful only in the boot that supplied it. Old records
40// without a boot remain readable, but cannot authorize namespace mutations.
41func (f *servingParkFS) checkBoot(expected string) error {
42 current, err := f.currentBoot()
43 if err != nil {
44 return err
45 }
46 if expected == "" || current != expected {
47 return hostbox.ErrChanged
48 }
49 return nil
50}
51
52func (f *servingParkFS) checkRecordBoot(r *servingParkRecord) error {
53 if r.Source.BootID != "" {
54 return f.checkBoot(r.Source.BootID)
55 }
56 b, err := servingParkReadBinding(f.state, "namespace")
57 if err != nil {
58 return err
59 }
60 if b != nil {
61 return hostbox.ErrChanged
62 }
63 return nil
64}
65