diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-05 02:42:41 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-05 02:52:50 +0900 |
| commit | eb5ee4fece0327b1183ae823d68e4cf4e3e1ced0 (patch) | |
| tree | 64e1c411e9d0a29637982519b9bd3a5ff6642d1a /internal/app/spruntime.go | |
| parent | 9462af08f38fefe40d985383d8825258a6d1f0a8 (diff) | |
internal/app: modularise outcome finalise
This is the initial effort of splitting up host and container side of finalisation for params to shim. The new layout also enables much finer grained unit testing of each step, as well as partition access to per-app state for each step.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/spruntime.go')
| -rw-r--r-- | internal/app/spruntime.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/app/spruntime.go b/internal/app/spruntime.go new file mode 100644 index 00000000..c2e5518d --- /dev/null +++ b/internal/app/spruntime.go @@ -0,0 +1,44 @@ +package app + +import ( + "hakurei.app/container" + "hakurei.app/hst" + "hakurei.app/system" + "hakurei.app/system/acl" +) + +// spRuntimeOp sets up XDG_RUNTIME_DIR inside the container. +type spRuntimeOp struct{} + +func (s spRuntimeOp) toSystem(state *outcomeStateSys, _ *hst.Config) error { + runtimeDir, runtimeDirInst := s.commonPaths(state.outcomeState) + state.sys.Ensure(runtimeDir, 0700) + state.sys.UpdatePermType(system.User, runtimeDir, acl.Execute) + state.sys.Ensure(runtimeDirInst, 0700) + state.sys.UpdatePermType(system.User, runtimeDirInst, acl.Read, acl.Write, acl.Execute) + return nil +} + +func (s spRuntimeOp) toContainer(state *outcomeStateParams) error { + const ( + xdgRuntimeDir = "XDG_RUNTIME_DIR" + xdgSessionClass = "XDG_SESSION_CLASS" + xdgSessionType = "XDG_SESSION_TYPE" + ) + + state.runtimeDir = container.AbsFHSRunUser.Append(state.mapuid.String()) + state.env[xdgRuntimeDir] = state.runtimeDir.String() + state.env[xdgSessionClass] = "user" + state.env[xdgSessionType] = "tty" + + _, runtimeDirInst := s.commonPaths(state.outcomeState) + state.params.Tmpfs(container.AbsFHSRunUser, 1<<12, 0755) + state.params.Bind(runtimeDirInst, state.runtimeDir, container.BindWritable) + return nil +} + +func (s spRuntimeOp) commonPaths(state *outcomeState) (runtimeDir, runtimeDirInst *container.Absolute) { + runtimeDir = state.sc.SharePath.Append("runtime") + runtimeDirInst = runtimeDir.Append(state.identity.String()) + return +} |
