aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/spruntime.go
blob: 54281c1b558de9aef7754ebc98a7834126383941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package app

import (
	"encoding/gob"

	"hakurei.app/container/bits"
	"hakurei.app/container/check"
	"hakurei.app/container/fhs"
	"hakurei.app/system"
	"hakurei.app/system/acl"
)

func init() { gob.Register(spRuntimeOp{}) }

// spRuntimeOp sets up XDG_RUNTIME_DIR inside the container.
type spRuntimeOp struct{}

func (s spRuntimeOp) toSystem(state *outcomeStateSys) 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 = fhs.AbsRunUser.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(fhs.AbsRunUser, 1<<12, 0755)
	state.params.Bind(runtimeDirInst, state.runtimeDir, bits.BindWritable)
	return nil
}

func (s spRuntimeOp) commonPaths(state *outcomeState) (runtimeDir, runtimeDirInst *check.Absolute) {
	runtimeDir = state.sc.SharePath.Append("runtime")
	runtimeDirInst = runtimeDir.Append(state.identity.String())
	return
}