aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/dbus/dbus.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-07-02 21:52:07 +0900
committerOphestra <cat@gensokyo.uk>2025-07-02 21:52:07 +0900
commit82561d62b66f17c05604e87f18187bb3a91f00d2 (patch)
treec1543f85b4458b7d5cb2cf7b1baa9dee318debfe /system/dbus/dbus.go
parenteec021cc4b4eb42bc9c8311755826828bfba1996 (diff)
system: move system access packages
These packages loosely belong in the "system" package and "system" provides high level wrappers for all of them. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/dbus/dbus.go')
-rw-r--r--system/dbus/dbus.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/system/dbus/dbus.go b/system/dbus/dbus.go
new file mode 100644
index 00000000..c5b4e812
--- /dev/null
+++ b/system/dbus/dbus.go
@@ -0,0 +1,40 @@
+// Package dbus wraps xdg-dbus-proxy and implements configuration and sandboxing of the underlying helper process.
+package dbus
+
+import (
+ "fmt"
+ "os"
+ "sync"
+)
+
+const (
+ SessionBusAddress = "DBUS_SESSION_BUS_ADDRESS"
+ SystemBusAddress = "DBUS_SYSTEM_BUS_ADDRESS"
+)
+
+var (
+ addresses [2]string
+ addressOnce sync.Once
+)
+
+func Address() (session, system string) {
+ addressOnce.Do(func() {
+ // resolve upstream session bus address
+ if addr, ok := os.LookupEnv(SessionBusAddress); !ok {
+ // fall back to default format
+ addresses[0] = fmt.Sprintf("unix:path=/run/user/%d/bus", os.Getuid())
+ } else {
+ addresses[0] = addr
+ }
+
+ // resolve upstream system bus address
+ if addr, ok := os.LookupEnv(SystemBusAddress); !ok {
+ // fall back to default hardcoded value
+ addresses[1] = "unix:path=/run/dbus/system_bus_socket"
+ } else {
+ addresses[1] = addr
+ }
+ })
+
+ return addresses[0], addresses[1]
+}