2017-03-02 00:49:45 +00:00
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2017-10-23 19:34:05 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2017-03-02 00:49:45 +00:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2017-10-23 19:34:05 +00:00
|
|
|
const defaultSystemBusAddress = "unix:path=/opt/local/var/run/dbus/system_bus_socket"
|
|
|
|
|
|
|
|
func getSessionBusPlatformAddress() (string, error) {
|
2017-03-02 00:49:45 +00:00
|
|
|
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if len(b) == 0 {
|
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
|
|
|
}
|
|
|
|
|
2017-10-23 19:34:05 +00:00
|
|
|
return "unix:path=" + string(b[:len(b)-1]), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSystemBusPlatformAddress() string {
|
|
|
|
address := os.Getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET")
|
|
|
|
if address != "" {
|
|
|
|
return fmt.Sprintf("unix:path=%s", address)
|
|
|
|
}
|
|
|
|
return defaultSystemBusAddress
|
2017-03-02 00:49:45 +00:00
|
|
|
}
|