internal/app: relocate state initialisation
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m9s
Test / Hakurei (push) Successful in 3m4s
Test / Hpkg (push) Successful in 4m4s
Test / Sandbox (race detector) (push) Successful in 4m37s
Test / Hakurei (race detector) (push) Successful in 5m18s
Test / Flake checks (push) Successful in 1m28s

This is useful for testing.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-10-10 20:12:05 +09:00
parent f6dd9dab6a
commit 24de7c50a0
5 changed files with 19 additions and 24 deletions

View File

@@ -2,7 +2,6 @@ package app
import (
"errors"
"os"
"strconv"
"hakurei.app/container"
@@ -72,10 +71,16 @@ func (s *outcomeState) valid() bool {
s.EnvPaths != nil
}
// populateEarly populates exported fields via syscallDispatcher.
// This must only be called from the priv side.
func (s *outcomeState) populateEarly(k syscallDispatcher, msg message.Msg) {
s.Shim = &shimParams{PrivPID: os.Getpid(), Verbose: msg.IsVerbose()}
// newOutcomeState returns the address of a new outcomeState with its exported fields populated via syscallDispatcher.
func newOutcomeState(k syscallDispatcher, msg message.Msg, id *state.ID, config *hst.Config, hsu *Hsu) *outcomeState {
s := outcomeState{
Shim: &shimParams{PrivPID: k.getpid(), Verbose: msg.IsVerbose()},
ID: id,
Identity: config.Identity,
UserID: hsu.MustIDMsg(msg),
EnvPaths: copyPaths(k),
Container: config.Container,
}
// enforce bounds and default early
if s.Container.WaitDelay < 0 {
@@ -94,7 +99,7 @@ func (s *outcomeState) populateEarly(k syscallDispatcher, msg message.Msg) {
s.Mapuid, s.Mapgid = k.overflowUid(msg), k.overflowGid(msg)
}
return
return &s
}
// populateLocal populates unexported fields from transmitted exported fields.