2017-03-02 00:49:45 +00:00
|
|
|
// +build !darwin
|
|
|
|
|
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
2017-10-23 19:34:05 +00:00
|
|
|
"fmt"
|
2017-03-02 00:49:45 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2017-10-23 19:34:05 +00:00
|
|
|
const defaultSystemBusAddress = "unix:path=/var/run/dbus/system_bus_socket"
|
|
|
|
|
|
|
|
func getSessionBusPlatformAddress() (string, error) {
|
2017-03-02 00:49:45 +00:00
|
|
|
cmd := exec.Command("dbus-launch")
|
|
|
|
b, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
if err != nil {
|
2017-10-23 19:34:05 +00:00
|
|
|
return "", err
|
2017-03-02 00:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i := bytes.IndexByte(b, '=')
|
|
|
|
j := bytes.IndexByte(b, '\n')
|
|
|
|
|
|
|
|
if i == -1 || j == -1 {
|
2017-10-23 19:34:05 +00:00
|
|
|
return "", errors.New("dbus: couldn't determine address of session bus")
|
2017-03-02 00:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
env, addr := string(b[0:i]), string(b[i+1:j])
|
|
|
|
os.Setenv(env, addr)
|
|
|
|
|
2017-10-23 19:34:05 +00:00
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSystemBusPlatformAddress() string {
|
|
|
|
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
|
|
|
|
if address != "" {
|
|
|
|
return fmt.Sprintf("unix:path=%s", address)
|
|
|
|
}
|
|
|
|
return defaultSystemBusAddress
|
2017-03-02 00:49:45 +00:00
|
|
|
}
|