2019-01-12 04:58:27 +00:00
|
|
|
// +build !darwin
|
|
|
|
|
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"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=/var/run/dbus/system_bus_socket"
|
|
|
|
|
|
|
|
func getSessionBusPlatformAddress() (string, error) {
|
2019-01-12 04:58:27 +00:00
|
|
|
cmd := exec.Command("dbus-launch")
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
i := bytes.IndexByte(b, '=')
|
|
|
|
j := bytes.IndexByte(b, '\n')
|
|
|
|
|
|
|
|
if i == -1 || j == -1 {
|
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
|
|
|
env, addr := string(b[0:i]), string(b[i+1:j])
|
|
|
|
os.Setenv(env, addr)
|
|
|
|
|
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSystemBusPlatformAddress() string {
|
|
|
|
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
|
|
|
|
if address != "" {
|
|
|
|
return fmt.Sprintf("unix:path=%s", address)
|
|
|
|
}
|
|
|
|
return defaultSystemBusAddress
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|