conn_other.go 428 B

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