aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/spdbus.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-05 02:42:41 +0900
committerOphestra <cat@gensokyo.uk>2025-10-05 02:52:50 +0900
commiteb5ee4fece0327b1183ae823d68e4cf4e3e1ced0 (patch)
tree64e1c411e9d0a29637982519b9bd3a5ff6642d1a /internal/app/spdbus.go
parent9462af08f38fefe40d985383d8825258a6d1f0a8 (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/spdbus.go')
-rw-r--r--internal/app/spdbus.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/app/spdbus.go b/internal/app/spdbus.go
new file mode 100644
index 00000000..42d523dd
--- /dev/null
+++ b/internal/app/spdbus.go
@@ -0,0 +1,50 @@
+package app
+
+import (
+ "hakurei.app/container"
+ "hakurei.app/hst"
+ "hakurei.app/system/acl"
+ "hakurei.app/system/dbus"
+)
+
+// spDBusOp maintains an xdg-dbus-proxy instance for the container.
+type spDBusOp struct {
+ // Whether to bind the system bus socket.
+ // Populated during toSystem.
+ ProxySystem bool
+}
+
+func (s *spDBusOp) toSystem(state *outcomeStateSys, config *hst.Config) error {
+ if config.SessionBus == nil {
+ config.SessionBus = dbus.NewConfig(config.ID, true, true)
+ }
+
+ // downstream socket paths
+ sessionPath, systemPath := state.instance().Append("bus"), state.instance().Append("system_bus_socket")
+
+ if err := state.sys.ProxyDBus(
+ config.SessionBus, config.SystemBus,
+ sessionPath, systemPath,
+ ); err != nil {
+ return err
+ }
+
+ state.sys.UpdatePerm(sessionPath, acl.Read, acl.Write)
+ if config.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 := container.AbsFHSRun.Append("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
+}