Skip to content

Commit

Permalink
Use the default fallback path for the session bus
Browse files Browse the repository at this point in the history
This is currently a de-facto standard done by most libraries, and is
being amended into the spec itself[1].

The previous behaviour (starting a new D-Bus server via dbus-launch) is
generally discouraged, since it will start a D-Bus at a non-standard
location and other processes have no mechanism via which they can locate
the bus socket.

[1]: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/395

Fixes: #372
  • Loading branch information
WhyNotHugo committed May 14, 2024
1 parent 7623695 commit 32346aa
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions conn_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package dbus

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -18,23 +17,12 @@ import (
var execCommand = exec.Command

Check failure on line 17 in conn_other.go

View workflow job for this annotation

GitHub Actions / lint

var `execCommand` is unused (unused)

func getSessionBusPlatformAddress() (string, error) {
cmd := execCommand("dbus-launch")
b, err := cmd.CombinedOutput()
if err != nil {
return "", err
}

i := bytes.IndexByte(b, '=')
j := bytes.IndexByte(b, '\n')

if i == -1 || j == -1 || i > j {
rundir, ok := os.LookupEnv("XDG_RUNTIME_DIR")
if !ok {
return "", errors.New("dbus: couldn't determine address of session bus")
}

env, addr := string(b[0:i]), string(b[i+1:j])
os.Setenv(env, addr)

return addr, nil
return path.Join(rundir, "bus"), nil
}

// tryDiscoverDbusSessionBusAddress tries to discover an existing dbus session
Expand Down

0 comments on commit 32346aa

Please sign in to comment.