From 38ef2b4d0caf48a5f6bb9d472b76764cbf14d23d Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Mon, 9 Sep 2024 03:16:54 +0900 Subject: app/dbus: manage dbus proxy and pass address to child This commit adds code that starts and registers the D-Bus proxy, as well as cleanup code that tracks and closes the daemon once our child exits. A few more flags were added to pass D-Bus config to xdg-dbus-proxy. Signed-off-by: Ophestra Umiker --- main.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 90276602..4aca72f3 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "errors" "flag" "fmt" @@ -9,6 +10,7 @@ import ( "strconv" "syscall" + "git.ophivana.moe/cat/fortify/dbus" "git.ophivana.moe/cat/fortify/internal/acl" "git.ophivana.moe/cat/fortify/internal/app" "git.ophivana.moe/cat/fortify/internal/state" @@ -17,7 +19,9 @@ import ( var ( Version = "impure" - a *app.App + + a *app.App + c *dbus.Config ) func tryVersion() { @@ -41,6 +45,21 @@ func main() { a = app.New(userName, flag.Args()) state.Set(*a.User, a.Command(), a.UID()) + // parse D-Bus config file if applicable + if mustDBus { + if dbusConfig == "builtin" { + c = dbus.NewConfig(dbusID, true, mpris) + } else { + if f, err := os.Open(dbusConfig); err != nil { + state.Fatal("Error opening D-Bus proxy config file:", err) + } else { + if err = json.NewDecoder(f).Decode(&c); err != nil { + state.Fatal("Error parsing D-Bus proxy config file:", err) + } + } + } + } + // ensure RunDir (e.g. `/run/user/%d/fortify`) if err := os.Mkdir(system.V.RunDir, 0700); err != nil && !errors.Is(err, fs.ErrExist) { state.Fatal("Error creating runtime directory:", err) @@ -103,7 +122,7 @@ func main() { } if mustDBus { - a.ShareDBus() + a.ShareDBus(c) } if mustPulse { -- cgit v1.3.1