net/dns: slightly optimize dbusPing for non-dbus case [Linux]
Avoid some work when D-Bus isn't running.
@@ -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
