Ophestra df9b77b077
All checks were successful
Test / Create distribution (push) Successful in 36s
Test / Sandbox (push) Successful in 2m11s
Test / Hpkg (push) Successful in 4m10s
Test / Sandbox (race detector) (push) Successful in 4m40s
Test / Hakurei (race detector) (push) Successful in 5m21s
Test / Hakurei (push) Successful in 2m18s
Test / Flake checks (push) Successful in 1m32s
internal/app: do not encode config early
Finalise no longer clobbers hst.Config.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-10-09 04:38:54 +09:00

50 lines
1.4 KiB
Go

// Package state provides cross-process state tracking for hakurei container instances.
package state
import (
"errors"
"time"
"hakurei.app/hst"
)
// ErrNoConfig is returned by [Cursor] when used with a nil [hst.Config].
var ErrNoConfig = errors.New("state does not contain config")
type Entries map[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(identity int, f func(c Cursor)) (ok bool, err error)
// List queries the store and returns a list of identities known to the store.
// Note that some or all returned identities might not have any active apps.
List() (identities []int, err error)
// Close releases any resources held by Store.
Close() error
}
// Cursor provides access to the store of an identity.
type Cursor interface {
Save(state *State) error
Destroy(id ID) error
Load() (Entries, error)
Len() (int, error)
}
// State is the on-disk state of a container instance.
type State struct {
// Unique instance id, generated by internal/app.
ID ID `json:"instance"`
// Shim process pid. This runs as the target user.
PID int `json:"pid"`
// Configuration value used to start the container.
Config *hst.Config `json:"config"`
// Exact point in time that the shim process was created.
Time time.Time `json:"time"`
}