From 21358cf2f5a7b35ec59f87c68e2537e8ad4ad8fb Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 11 Feb 2022 07:48:03 -0800 Subject: [PATCH] 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 --- net/dns/manager_linux.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/dns/manager_linux.go b/net/dns/manager_linux.go index b633d7fcf..843abca16 100644 --- a/net/dns/manager_linux.go +++ b/net/dns/manager_linux.go @@ -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