net/dns: slightly optimize dbusPing for non-dbus case [Linux]

Avoid some work when D-Bus isn't running.

Change-Id: I6f89bb75fdb24c13f61be9b400610772756db1ef
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/3914/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 37e7a387ff
commit 21358cf2f5

@ -321,15 +321,15 @@ func resolvedIsActuallyResolver(bs []byte) error {
}
func dbusPing(name, objectPath string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
conn, err := dbus.SystemBus()
if err != nil {
// DBus probably not running.
return err
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
obj := conn.Object(name, dbus.ObjectPath(objectPath))
call := obj.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", 0)
return call.Err

Loading…
Cancel
Save