Add GetGlobalConn

This commit is contained in:
Laurence Withers 2026-01-18 12:48:32 +00:00
parent b83a572500
commit ffb40d7843
1 changed files with 8 additions and 3 deletions

View File

@ -26,7 +26,7 @@ const (
// error otherwise. It will attempt to establish a connection to the journal
// if there is not already one in progress.
func CheckConnection() error {
_, err := getGlobal()
_, err := GetGlobalConn()
return err
}
@ -39,7 +39,12 @@ func SetGlobalConn(c *Conn) {
global = c
}
func getGlobal() (*Conn, error) {
// GetGlobalConn returns the global (default) connection to the journal. It may
// return an error if no connection could be established. If no connection is
// yet established, it will attempt to establish one. This is rate limited to
// avoid excessive connection attempts should there be a persistent problem
// connecting to the journal socket.
func GetGlobalConn() (*Conn, error) {
globalLock.Lock()
defer globalLock.Unlock()
@ -119,7 +124,7 @@ func SetGlobalErrHandler(errHandler func(err error)) {
// Note: to avoid allocation / garbage, ensure attrs has capacity for an extra
// 2+len(GlobalCommonAttr) values.
func Entry(pri Priority, msg string, attrs []Attr) {
c, _ := getGlobal()
c, _ := GetGlobalConn()
if c == nil {
return
}