All checks were successful
Test / Create distribution (push) Successful in 26s
Test / Sandbox (push) Successful in 1m44s
Test / Fortify (push) Successful in 2m37s
Test / Sandbox (race detector) (push) Successful in 2m59s
Test / Fpkg (push) Successful in 3m34s
Test / Fortify (race detector) (push) Successful in 4m6s
Test / Flake checks (push) Successful in 59s
This reduces the scope of the fst package, which was growing questionably large. Signed-off-by: Ophestra <cat@gensokyo.uk>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package state
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"time"
|
|
|
|
"git.gensokyo.uk/security/fortify/fst"
|
|
"git.gensokyo.uk/security/fortify/internal/app"
|
|
)
|
|
|
|
var ErrNoConfig = errors.New("state does not contain config")
|
|
|
|
type Entries map[app.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, configWriter io.WriterTo) error
|
|
Destroy(id app.ID) error
|
|
Load() (Entries, error)
|
|
Len() (int, error)
|
|
}
|
|
|
|
// State is a fortify process's state
|
|
type State struct {
|
|
// fortify instance id
|
|
ID app.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 `json:"time"`
|
|
}
|