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>
This commit is contained in:
Brad Fitzpatrick 2022-02-11 07:48:03 -08:00 committed by Brad Fitzpatrick
parent 37e7a387ff
commit 21358cf2f5

View File

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