From 32eb4232a8e435b983a0d378f224d652db71faf2 Mon Sep 17 00:00:00 2001 From: delthas Date: Tue, 29 Aug 2023 13:47:48 +0200 Subject: [PATCH] Accept connection options in shared bus getters It could be useful for apps to try to pass connection options when connecting to the bus, ignoring them if the bus is already connected. This avoids having to manage the shared bus in the app when specifying connection options. --- conn.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conn.go b/conn.go index bbe111b2..d1f1bbd0 100644 --- a/conn.go +++ b/conn.go @@ -57,7 +57,7 @@ type Conn struct { // SessionBus returns a shared connection to the session bus, connecting to it // if not already done. -func SessionBus() (conn *Conn, err error) { +func SessionBus(opts ...ConnOption) (conn *Conn, err error) { sessionBusLck.Lock() defer sessionBusLck.Unlock() if sessionBus != nil && @@ -69,7 +69,7 @@ func SessionBus() (conn *Conn, err error) { sessionBus = conn } }() - conn, err = ConnectSessionBus() + conn, err = ConnectSessionBus(opts...) return } @@ -116,7 +116,7 @@ func SessionBusPrivateHandler(handler Handler, signalHandler SignalHandler) (*Co // SystemBus returns a shared connection to the system bus, connecting to it if // not already done. -func SystemBus() (conn *Conn, err error) { +func SystemBus(opts ...ConnOption) (conn *Conn, err error) { systemBusLck.Lock() defer systemBusLck.Unlock() if systemBus != nil && @@ -128,7 +128,7 @@ func SystemBus() (conn *Conn, err error) { systemBus = conn } }() - conn, err = ConnectSystemBus() + conn, err = ConnectSystemBus(opts...) return }