aboutsummaryrefslogtreecommitdiffhomepage
path: root/system
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-05 02:07:56 +0900
committerOphestra <cat@gensokyo.uk>2025-09-05 02:07:56 +0900
commit197fa65b8fc8f35270df9cef68442b6a9c380ae1 (patch)
tree2fbb1612f5332017ff69e28d8a16745e51b58674 /system
parente81a45e849e7a85f50da04041d0f7a28b0fcc3cc (diff)
system/dbus: remove redundant proxy pairs
This is left over from before dbus.Final. Remove them now as they serve no purpose. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system')
-rw-r--r--system/dbus.go31
-rw-r--r--system/dbus/address.go7
2 files changed, 25 insertions, 13 deletions
diff --git a/system/dbus.go b/system/dbus.go
index d1ff06ae..76939890 100644
--- a/system/dbus.go
+++ b/system/dbus.go
@@ -6,10 +6,12 @@ import (
"errors"
"fmt"
"log"
+ "reflect"
"strings"
"sync"
"syscall"
+ "hakurei.app/container"
"hakurei.app/system/dbus"
)
@@ -39,10 +41,11 @@ func (sys *I) ProxyDBus(session, system *dbus.Config, sessionPath, systemPath st
// system bus is optional
d.system = system != nil
- d.sessionBus[0], d.systemBus[0] = dbus.Address()
- d.sessionBus[1], d.systemBus[1] = sessionPath, systemPath
+ var sessionBus, systemBus dbus.ProxyPair
+ sessionBus[0], systemBus[0] = dbus.Address()
+ sessionBus[1], systemBus[1] = sessionPath, systemPath
d.out = &linePrefixWriter{println: log.Println, prefix: "(dbus) ", msg: new(strings.Builder)}
- if final, err := dbus.Finalise(d.sessionBus, d.systemBus, session, system); err != nil {
+ if final, err := dbus.Finalise(sessionBus, systemBus, session, system); err != nil {
if errors.Is(err, syscall.EINVAL) {
return nil, newOpErrorMessage("dbus", err,
"message bus proxy configuration contains NUL byte", false)
@@ -51,9 +54,9 @@ func (sys *I) ProxyDBus(session, system *dbus.Config, sessionPath, systemPath st
fmt.Sprintf("cannot finalise message bus proxy: %v", err), false)
} else {
if msg.IsVerbose() {
- msg.Verbose("session bus proxy:", session.Args(d.sessionBus))
+ msg.Verbose("session bus proxy:", session.Args(sessionBus))
if system != nil {
- msg.Verbose("system bus proxy:", system.Args(d.systemBus))
+ msg.Verbose("system bus proxy:", system.Args(systemBus))
}
// this calls the argsWt String method
@@ -76,16 +79,14 @@ type DBusProxyOp struct {
out *linePrefixWriter
// whether system bus proxy is enabled
system bool
-
- sessionBus, systemBus dbus.ProxyPair
}
func (d *DBusProxyOp) Type() Enablement { return Process }
func (d *DBusProxyOp) apply(sys *I) error {
- msg.Verbosef("session bus proxy on %q for upstream %q", d.sessionBus[1], d.sessionBus[0])
+ msg.Verbosef("session bus proxy on %q for upstream %q", d.final.Session[1], d.final.Session[0])
if d.system {
- msg.Verbosef("system bus proxy on %q for upstream %q", d.systemBus[1], d.systemBus[0])
+ msg.Verbosef("system bus proxy on %q for upstream %q", d.final.System[1], d.final.System[0])
}
d.proxy = dbus.New(sys.ctx, d.final, d.out)
@@ -115,12 +116,16 @@ func (d *DBusProxyOp) revert(*I, *Criteria) error {
func (d *DBusProxyOp) Is(o Op) bool {
target, ok := o.(*DBusProxyOp)
return ok && d != nil && target != nil &&
- ((d.proxy == nil && target.proxy == nil) ||
- (d.proxy != nil && target.proxy != nil &&
- d.proxy.String() == target.proxy.String()))
+ d.system == target.system &&
+ d.final != nil && target.final != nil &&
+ d.final.Session == target.final.Session &&
+ d.final.System == target.final.System &&
+ dbus.EqualAddrEntries(d.final.SessionUpstream, target.final.SessionUpstream) &&
+ dbus.EqualAddrEntries(d.final.SystemUpstream, target.final.SystemUpstream) &&
+ reflect.DeepEqual(d.final.WriterTo, target.final.WriterTo)
}
-func (d *DBusProxyOp) Path() string { return "(dbus proxy)" }
+func (d *DBusProxyOp) Path() string { return container.Nonexistent }
func (d *DBusProxyOp) String() string { return d.proxy.String() }
// linePrefixWriter calls println with a prefix for every line written.
diff --git a/system/dbus/address.go b/system/dbus/address.go
index bec49e62..edee7e20 100644
--- a/system/dbus/address.go
+++ b/system/dbus/address.go
@@ -13,6 +13,13 @@ type AddrEntry struct {
Values [][2]string `json:"values"`
}
+// EqualAddrEntries returns whether two slices of [AddrEntry] are equal.
+func EqualAddrEntries(entries, target []AddrEntry) bool {
+ return slices.EqualFunc(entries, target, func(a AddrEntry, b AddrEntry) bool {
+ return a.Method == b.Method && slices.Equal(a.Values, b.Values)
+ })
+}
+
// Parse parses D-Bus address according to
// https://dbus.freedesktop.org/doc/dbus-specification.html#addresses
func Parse(addr []byte) ([]AddrEntry, error) {