2019-01-12 04:58:27 +00:00
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2019-09-27 21:51:53 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2019-01-12 04:58:27 +00:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2019-09-27 21:51:53 +00:00
|
|
|
const defaultSystemBusAddress = "unix:path=/opt/local/var/run/dbus/system_bus_socket"
|
|
|
|
|
|
|
|
func getSessionBusPlatformAddress() (string, error) {
|
2019-01-12 04:58:27 +00:00
|
|
|
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
|
|
|
|
b, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
if err != nil {
|
2019-09-27 21:51:53 +00:00
|
|
|
return "", err
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(b) == 0 {
|
2019-09-27 21:51:53 +00:00
|
|
|
return "", errors.New("dbus: couldn't determine address of session bus")
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 21:51:53 +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
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|
2019-12-12 01:27:03 +00:00
|
|
|
|
|
|
|
func tryDiscoverDbusSessionBusAddress() string {
|
|
|
|
return ""
|
|
|
|
}
|