diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-10 03:19:09 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-10 03:19:09 +0900 |
| commit | 109aaee6593ac6e72d23b817e5b75292c2ed7bed (patch) | |
| tree | 459fbd8f8c0685b33002fb1f9c101c9b39a38b6a /internal/app/outcome.go | |
| parent | 22ee5ae151fa991cf23dbf1b3efb5a0d6fb9b092 (diff) | |
internal/app: copy parts of config to state
This is less error-prone than passing the address to the entire hst.Config struct, and reduces the likelihood of accidentally clobbering hst.Config. This also improves ease of testing.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/outcome.go')
| -rw-r--r-- | internal/app/outcome.go | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/internal/app/outcome.go b/internal/app/outcome.go index c5f0fa7a..84a4bae3 100644 --- a/internal/app/outcome.go +++ b/internal/app/outcome.go @@ -134,7 +134,7 @@ func (s *outcomeState) instancePath() *check.Absolute { return s.sc.SharePath.Ap func (s *outcomeState) runtimePath() *check.Absolute { return s.sc.RunDirPath.Append(s.id.String()) } // outcomeStateSys wraps outcomeState and [system.I]. Used on the priv side only. -// Implementations of outcomeOp must not access fields other than sys and config unless explicitly stated. +// Implementations of outcomeOp must not access fields other than sys unless explicitly stated. type outcomeStateSys struct { // Whether XDG_RUNTIME_DIR is used post hsu. useRuntimeDir bool @@ -142,13 +142,33 @@ type outcomeStateSys struct { sharePath *check.Absolute // Process-specific directory in XDG_RUNTIME_DIR, nil if unused. runtimeSharePath *check.Absolute - // Must not be modified by outcomeOp. - config *hst.Config + + // Copied from [hst.Config]. Safe for read by outcomeOp.toSystem. + appId string + // Copied from [hst.Config]. Safe for read by outcomeOp.toSystem. + et hst.Enablement + + // Copied from [hst.Config]. Safe for read by spWaylandOp.toSystem only. + directWayland bool + // Copied header from [hst.Config]. Safe for read by spFinalOp.toSystem only. + extraPerms []*hst.ExtraPermConfig + // Copied address from [hst.Config. Safe for read by spDBusOp.toSystem only. + sessionBus, systemBus *hst.BusConfig sys *system.I *outcomeState } +// outcomeState returns the address of a new outcomeStateSys embedding the current outcomeState. +func (s *outcomeState) newSys(config *hst.Config, sys *system.I) *outcomeStateSys { + return &outcomeStateSys{ + appId: config.ID, et: config.Enablements.Unwrap(), + directWayland: config.DirectWayland, extraPerms: config.ExtraPerms, + sessionBus: config.SessionBus, systemBus: config.SystemBus, + sys: sys, outcomeState: s, + } +} + // ensureRuntimeDir must be called if access to paths within XDG_RUNTIME_DIR is required. func (state *outcomeStateSys) ensureRuntimeDir() { if state.useRuntimeDir { @@ -245,7 +265,7 @@ func (state *outcomeStateSys) toSystem() error { &spPulseOp{}, &spDBusOp{}, - spFinal{}, + spFinalOp{}, } state.Shim.Ops = make([]outcomeOp, 0, len(ops)) |
