2014-02-21 04:34:06 -05:00
|
|
|
// +build !darwin
|
|
|
|
|
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
2016-04-19 17:51:43 -04:00
|
|
|
"os"
|
2014-02-21 04:34:06 -05:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
func sessionBusPlatform() (*Conn, error) {
|
|
|
|
cmd := exec.Command("dbus-launch")
|
|
|
|
b, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
i := bytes.IndexByte(b, '=')
|
|
|
|
j := bytes.IndexByte(b, '\n')
|
|
|
|
|
|
|
|
if i == -1 || j == -1 {
|
|
|
|
return nil, errors.New("dbus: couldn't determine address of session bus")
|
|
|
|
}
|
|
|
|
|
2016-04-19 17:51:43 -04:00
|
|
|
env, addr := string(b[0:i]), string(b[i+1:j])
|
|
|
|
os.Setenv(env, addr)
|
|
|
|
|
|
|
|
return Dial(addr)
|
2014-02-21 04:34:06 -05:00
|
|
|
}
|