aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/state/state.go
blob: e8208476c090119082d8a174d8eeb3ed288fe128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package state

import (
	"time"

	"git.gensokyo.uk/security/fortify/fst"
)

type Entries map[fst.ID]*State

type Store interface {
	// Do calls f exactly once and ensures store exclusivity until f returns.
	// Returns whether f is called and any errors during the locking process.
	// Cursor provided to f becomes invalid as soon as f returns.
	Do(aid int, f func(c Cursor)) (ok bool, err error)

	// List queries the store and returns a list of aids known to the store.
	// Note that some or all returned aids might not have any active apps.
	List() (aids []int, err error)

	// Close releases any resources held by Store.
	Close() error
}

// Cursor provides access to the store
type Cursor interface {
	Save(state *State) error
	Destroy(id fst.ID) error
	Load() (Entries, error)
	Len() (int, error)
}

// State is the on-disk format for a fortified process's state information
type State struct {
	// fortify instance id
	ID fst.ID `json:"instance"`
	// child process PID value
	PID int `json:"pid"`
	// sealed app configuration
	Config *fst.Config `json:"config"`

	// process start time
	Time time.Time
}