2024-09-22 00:29:36 +09:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2024-10-16 14:38:57 +09:00
|
|
|
|
2024-12-18 15:50:46 +09:00
|
|
|
"git.ophivana.moe/security/fortify/fst"
|
2024-09-22 00:29:36 +09:00
|
|
|
)
|
|
|
|
|
2024-12-19 21:36:17 +09:00
|
|
|
type Entries map[fst.ID]*State
|
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
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.
|
2024-12-19 21:36:17 +09:00
|
|
|
// 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)
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// Close releases any resources held by Store.
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2024-12-19 21:36:17 +09:00
|
|
|
// Cursor provides access to the store
|
|
|
|
type Cursor interface {
|
2024-09-22 00:29:36 +09:00
|
|
|
Save(state *State) error
|
2024-12-19 21:36:17 +09:00
|
|
|
Destroy(id fst.ID) error
|
|
|
|
Load() (Entries, error)
|
2024-09-22 00:29:36 +09:00
|
|
|
Len() (int, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// State is the on-disk format for a fortified process's state information
|
|
|
|
type State struct {
|
2024-12-18 13:45:55 +09:00
|
|
|
// fortify instance id
|
2024-12-18 15:50:46 +09:00
|
|
|
ID fst.ID `json:"instance"`
|
2024-09-22 00:29:36 +09:00
|
|
|
// child process PID value
|
2024-12-18 13:45:55 +09:00
|
|
|
PID int `json:"pid"`
|
|
|
|
// sealed app configuration
|
2024-12-18 15:50:46 +09:00
|
|
|
Config *fst.Config `json:"config"`
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// process start time
|
|
|
|
Time time.Time
|
|
|
|
}
|