2016-01-21 04:19:15 +01:00
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2017-10-05 16:20:47 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2016-01-21 04:19:15 +01:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2017-10-05 16:20:47 +02:00
|
|
|
const defaultSystemBusAddress = "unix:path=/opt/local/var/run/dbus/system_bus_socket"
|
|
|
|
|
2016-12-16 12:55:26 +01:00
|
|
|
func getSessionBusPlatformAddress() (string, error) {
|
2016-01-21 04:19:15 +01:00
|
|
|
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
|
|
|
|
b, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
if err != nil {
|
2016-12-16 12:55:26 +01:00
|
|
|
return "", err
|
2016-01-21 04:19:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(b) == 0 {
|
2016-12-16 12:55:26 +01:00
|
|
|
return "", errors.New("dbus: couldn't determine address of session bus")
|
2016-01-21 04:19:15 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 12:55:26 +01:00
|
|
|
return "unix:path=" + string(b[:len(b)-1]), nil
|
2016-01-21 04:19:15 +01:00
|
|
|
}
|
2017-10-05 16:20:47 +02:00
|
|
|
|
|
|
|
func getSystemBusPlatformAddress() string {
|
|
|
|
address := os.Getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET")
|
|
|
|
if address != "" {
|
|
|
|
return fmt.Sprintf("unix:path=%s", address)
|
|
|
|
}
|
|
|
|
return defaultSystemBusAddress
|
|
|
|
}
|
2019-02-13 14:12:12 +01:00
|
|
|
|
|
|
|
func tryDiscoverDbusSessionBusAddress() string {
|
|
|
|
return ""
|
|
|
|
}
|