aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/outcome/spdbus.go
blob: a50f9cd2a369f2358f20632d6a4efaf566e98691 (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
50
51
52
53
54
55
56
57
58
59
package outcome

import (
	"encoding/gob"

	"hakurei.app/fhs"
	"hakurei.app/hst"
	"hakurei.app/internal/acl"
	"hakurei.app/internal/dbus"
)

func init() { gob.Register(new(spDBusOp)) }

// spDBusOp maintains an xdg-dbus-proxy instance for the container.
//
// Runs after spRuntimeOp.
type spDBusOp struct {
	// Whether to bind the system bus socket. Populated during toSystem.
	ProxySystem bool
}

func (s *spDBusOp) toSystem(state *outcomeStateSys) error {
	if state.et&hst.EDBus == 0 {
		return errNotEnabled
	}

	if state.sessionBus == nil {
		state.sessionBus = dbus.NewConfig(state.appId, true, true)
	}

	// downstream socket paths
	sessionPath, systemPath := state.instance().Append("bus"), state.instance().Append("system_bus_socket")

	var sessionBus, systemBus dbus.ProxyPair
	sessionBus[0], systemBus[0] = state.k.dbusAddress()
	sessionBus[1], systemBus[1] = sessionPath.String(), systemPath.String()
	if err := state.sys.ProxyDBus(state.sessionBus, state.systemBus, sessionBus, systemBus); err != nil {
		return err
	}

	state.sys.UpdatePerm(sessionPath, acl.Read, acl.Write)
	if state.systemBus != nil {
		s.ProxySystem = true
		state.sys.UpdatePerm(systemPath, acl.Read, acl.Write)
	}
	return nil
}

func (s *spDBusOp) toContainer(state *outcomeStateParams) error {
	sessionInner := state.runtimeDir.Append("bus")
	state.env["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=" + sessionInner.String()
	state.params.Bind(state.instancePath().Append("bus"), sessionInner, 0)
	if s.ProxySystem {
		systemInner := fhs.AbsVar.Append("run/dbus/system_bus_socket")
		state.env["DBUS_SYSTEM_BUS_ADDRESS"] = "unix:path=" + systemInner.String()
		state.params.Bind(state.instancePath().Append("system_bus_socket"), systemInner, 0)
	}
	return nil
}