conn_other.go 490 B

12345678910111213141516171819202122232425262728293031
  1. // +build !darwin
  2. package dbus
  3. import (
  4. "bytes"
  5. "errors"
  6. "os"
  7. "os/exec"
  8. )
  9. func sessionBusPlatform() (*Conn, error) {
  10. cmd := exec.Command("dbus-launch")
  11. b, err := cmd.CombinedOutput()
  12. if err != nil {
  13. return nil, err
  14. }
  15. i := bytes.IndexByte(b, '=')
  16. j := bytes.IndexByte(b, '\n')
  17. if i == -1 || j == -1 {
  18. return nil, errors.New("dbus: couldn't determine address of session bus")
  19. }
  20. env, addr := string(b[0:i]), string(b[i+1:j])
  21. os.Setenv(env, addr)
  22. return Dial(addr)
  23. }