diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-29 04:32:43 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-29 04:33:13 +0900 |
| commit | a0b4e47acc228e48165966d8e139277b8f6f450e (patch) | |
| tree | d363a6781536ce946aa445271ca1d3df587e6031 /internal/outcome/spdbus.go | |
| parent | a52f7038e5a607dd0901244abb791c96deaf9c2d (diff) | |
internal/outcome: rename from app
This is less ambiguous, and more accurately describes the purpose of the package.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/outcome/spdbus.go')
| -rw-r--r-- | internal/outcome/spdbus.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/outcome/spdbus.go b/internal/outcome/spdbus.go new file mode 100644 index 00000000..afb62ca0 --- /dev/null +++ b/internal/outcome/spdbus.go @@ -0,0 +1,58 @@ +package outcome + +import ( + "encoding/gob" + + "hakurei.app/container/fhs" + "hakurei.app/hst" + "hakurei.app/system/acl" + "hakurei.app/system/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 +} |
