2016-01-21 04:19:15 +01:00
|
|
|
// +build !darwin
|
|
|
|
|
|
|
|
package dbus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
2017-10-05 16:20:47 +02:00
|
|
|
"fmt"
|
2016-12-16 12:55:26 +01:00
|
|
|
"os"
|
2016-01-21 04:19:15 +01:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2017-10-05 16:20:47 +02:00
|
|
|
const defaultSystemBusAddress = "unix:path=/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("dbus-launch")
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
i := bytes.IndexByte(b, '=')
|
|
|
|
j := bytes.IndexByte(b, '\n')
|
|
|
|
|
|
|
|
if i == -1 || j == -1 {
|
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
|
|
|
env, addr := string(b[0:i]), string(b[i+1:j])
|
|
|
|
os.Setenv(env, addr)
|
|
|
|
|
|
|
|
return addr, nil
|
2016-01-21 04:19:15 +01:00
|
|
|
}
|
2017-10-05 16:20:47 +02:00
|
|
|
|
|
|
|
func getSystemBusPlatformAddress() string {
|
|
|
|
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
|
|
|
|
if address != "" {
|
|
|
|
return fmt.Sprintf("unix:path=%s", address)
|
|
|
|
}
|
|
|
|
return defaultSystemBusAddress
|
|
|
|
}
|