diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-14 01:33:44 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-14 01:33:44 +0900 |
| commit | 790d77075e40ee3162d7925e983f01747b5c2c89 (patch) | |
| tree | 56a59641aa87a40c9b28600ff8bd5d5642d95f5e /internal | |
| parent | e5ff40e7d32d28cace183cd2c80f40f142855ff5 (diff) | |
system/dbus: remove builder state leak
This enables external testing of system.I state.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/app/app_test.go | 25 | ||||
| -rw-r--r-- | internal/app/dispatcher.go | 6 | ||||
| -rw-r--r-- | internal/app/dispatcher_test.go | 9 | ||||
| -rw-r--r-- | internal/app/spdbus.go | 11 |
4 files changed, 40 insertions, 11 deletions
diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 2f42f70a..c89910a7 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -25,6 +25,7 @@ import ( "hakurei.app/message" "hakurei.app/system" "hakurei.app/system/acl" + "hakurei.app/system/dbus" ) func TestApp(t *testing.T) { @@ -213,7 +214,7 @@ func TestApp(t *testing.T) { Ensure(m("/run/user/1971"), 0700).UpdatePermType(system.User, m("/run/user/1971"), acl.Execute). // this is ordered as is because the previous Ensure only calls mkdir if XDG_RUNTIME_DIR is unset Ephemeral(system.Process, m("/run/user/1971/hakurei/ebf083d1b175911782d413369b64ce7c"), 0700).UpdatePermType(system.Process, m("/run/user/1971/hakurei/ebf083d1b175911782d413369b64ce7c"), acl.Execute). Link(m("/run/user/1971/pulse/native"), m("/run/user/1971/hakurei/ebf083d1b175911782d413369b64ce7c/pulse")). - MustProxyDBus(m("/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/bus"), &hst.BusConfig{ + MustProxyDBus(&hst.BusConfig{ Talk: []string{ "org.freedesktop.Notifications", "org.freedesktop.FileManager1", @@ -235,13 +236,19 @@ func TestApp(t *testing.T) { "org.freedesktop.portal.*": "@/org/freedesktop/portal/*", }, Filter: true, - }, m("/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/system_bus_socket"), &hst.BusConfig{ + }, &hst.BusConfig{ Talk: []string{ "org.bluez", "org.freedesktop.Avahi", "org.freedesktop.UPower", }, Filter: true, + }, dbus.ProxyPair{ + "unix:path=/run/user/1971/bus", + "/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/bus", + }, dbus.ProxyPair{ + "unix:path=/var/run/dbus/system_bus_socket", + "/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/system_bus_socket", }). UpdatePerm(m("/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/bus"), acl.Read, acl.Write). UpdatePerm(m("/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/system_bus_socket"), acl.Read, acl.Write), @@ -364,7 +371,7 @@ func TestApp(t *testing.T) { Ephemeral(system.Process, m("/run/user/1971/hakurei/8e2c76b066dabe574cf073bdb46eb5c1"), 0700).UpdatePermType(system.Process, m("/run/user/1971/hakurei/8e2c76b066dabe574cf073bdb46eb5c1"), acl.Execute). Link(m("/run/user/1971/pulse/native"), m("/run/user/1971/hakurei/8e2c76b066dabe574cf073bdb46eb5c1/pulse")). Ephemeral(system.Process, m("/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1"), 0711). - MustProxyDBus(m("/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1/bus"), &hst.BusConfig{ + MustProxyDBus(&hst.BusConfig{ Talk: []string{ "org.freedesktop.FileManager1", "org.freedesktop.Notifications", "org.freedesktop.ScreenSaver", "org.freedesktop.secrets", @@ -377,13 +384,19 @@ func TestApp(t *testing.T) { }, Call: map[string]string{}, Broadcast: map[string]string{}, Filter: true, - }, m("/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1/system_bus_socket"), &hst.BusConfig{ + }, &hst.BusConfig{ Talk: []string{ "org.bluez", "org.freedesktop.Avahi", "org.freedesktop.UPower", }, Filter: true, + }, dbus.ProxyPair{ + "unix:path=/run/user/1971/bus", + "/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1/bus", + }, dbus.ProxyPair{ + "unix:path=/var/run/dbus/system_bus_socket", + "/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1/system_bus_socket", }). UpdatePerm(m("/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1/bus"), acl.Read, acl.Write). UpdatePerm(m("/tmp/hakurei.0/8e2c76b066dabe574cf073bdb46eb5c1/system_bus_socket"), acl.Read, acl.Write), @@ -739,6 +752,10 @@ func (k *stubNixOS) overflowGid(message.Msg) int { return 65534 } func (k *stubNixOS) mustHsuPath() *check.Absolute { return m("/proc/nonexistent/hsu") } +func (k *stubNixOS) dbusAddress() (string, string) { + return "unix:path=/run/user/1971/bus", "unix:path=/var/run/dbus/system_bus_socket" +} + func (k *stubNixOS) fatalf(format string, v ...any) { panic(fmt.Sprintf(format, v...)) } func (k *stubNixOS) isVerbose() bool { return true } diff --git a/internal/app/dispatcher.go b/internal/app/dispatcher.go index d56278a0..d298d6b6 100644 --- a/internal/app/dispatcher.go +++ b/internal/app/dispatcher.go @@ -13,6 +13,7 @@ import ( "hakurei.app/container/check" "hakurei.app/internal" "hakurei.app/message" + "hakurei.app/system/dbus" ) // osFile represents [os.File]. @@ -63,6 +64,9 @@ type syscallDispatcher interface { // mustHsuPath provides [internal.MustHsuPath]. mustHsuPath() *check.Absolute + // dbusAddress provides [dbus.Address]. + dbusAddress() (session, system string) + // fatalf provides [log.Fatalf]. fatalf(format string, v ...any) } @@ -99,4 +103,6 @@ func (direct) overflowGid(msg message.Msg) int { return container.OverflowGid(ms func (direct) mustHsuPath() *check.Absolute { return internal.MustHsuPath() } +func (k direct) dbusAddress() (session, system string) { return dbus.Address() } + func (direct) fatalf(format string, v ...any) { log.Fatalf(format, v...) } diff --git a/internal/app/dispatcher_test.go b/internal/app/dispatcher_test.go index 3e608c3f..d00170ad 100644 --- a/internal/app/dispatcher_test.go +++ b/internal/app/dispatcher_test.go @@ -97,7 +97,7 @@ func checkOpBehaviour(t *testing.T, testCases []opBehaviourTestCase) { if err := s.populateLocal(k, k); err != nil { t.Fatalf("populateLocal: error = %v", err) } - stateSys := s.newSys(config, newI()) + stateSys := s.newSys(config, system.New(panicMsgContext{}, k, checkExpectUid)) if tc.pStateSys != nil { tc.pStateSys(stateSys) } @@ -218,6 +218,12 @@ func (k *kstub) mustHsuPath() *check.Absolute { return k.Expects("mustHsuPath").Ret.(*check.Absolute) } +func (k *kstub) dbusAddress() (session, system string) { + k.Helper() + ret := k.Expects("dbusAddress").Ret.([2]string) + return ret[0], ret[1] +} + func (k *kstub) GetLogger() *log.Logger { panic("unreachable") } func (k *kstub) IsVerbose() bool { k.Helper(); return k.Expects("isVerbose").Ret.(bool) } @@ -320,4 +326,5 @@ func (panicDispatcher) cmdOutput(*exec.Cmd) ([]byte, error) { panic("unreachab func (panicDispatcher) overflowUid(message.Msg) int { panic("unreachable") } func (panicDispatcher) overflowGid(message.Msg) int { panic("unreachable") } func (panicDispatcher) mustHsuPath() *check.Absolute { panic("unreachable") } +func (panicDispatcher) dbusAddress() (string, string) { panic("unreachable") } func (panicDispatcher) fatalf(string, ...any) { panic("unreachable") } diff --git a/internal/app/spdbus.go b/internal/app/spdbus.go index b818cbe9..c2c1fefe 100644 --- a/internal/app/spdbus.go +++ b/internal/app/spdbus.go @@ -13,8 +13,7 @@ func init() { gob.Register(new(spDBusOp)) } // spDBusOp maintains an xdg-dbus-proxy instance for the container. type spDBusOp struct { - // Whether to bind the system bus socket. - // Populated during toSystem. + // Whether to bind the system bus socket. Populated during toSystem. ProxySystem bool } @@ -30,10 +29,10 @@ func (s *spDBusOp) toSystem(state *outcomeStateSys) error { // downstream socket paths sessionPath, systemPath := state.instance().Append("bus"), state.instance().Append("system_bus_socket") - if err := state.sys.ProxyDBus( - state.sessionBus, state.systemBus, - sessionPath, systemPath, - ); err != nil { + 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 } |
