mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-29 19:43:57 +01:00
a78fd69f80
Added host configurators for Linux, Windows, and macOS. The host configurator will update the peer system configuration directing DNS queries according to its capabilities. Some Linux distributions don't support split (match) DNS or custom ports, and that will be reported to our management system in another PR
42 lines
869 B
Go
42 lines
869 B
Go
package dns
|
|
|
|
import (
|
|
"context"
|
|
"github.com/godbus/dbus/v5"
|
|
log "github.com/sirupsen/logrus"
|
|
"time"
|
|
)
|
|
|
|
const dbusDefaultFlag = 0
|
|
|
|
func isDbusListenerRunning(dest string, path dbus.ObjectPath) bool {
|
|
obj, closeConn, err := getDbusObject(dest, path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
defer closeConn()
|
|
|
|
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", 0).Store()
|
|
return err == nil
|
|
}
|
|
|
|
func getDbusObject(dest string, path dbus.ObjectPath) (dbus.BusObject, func(), error) {
|
|
conn, err := dbus.SystemBus()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
obj := conn.Object(dest, path)
|
|
|
|
closeFunc := func() {
|
|
closeErr := conn.Close()
|
|
if closeErr != nil {
|
|
log.Warnf("got an error closing dbus connection, err: %s", closeErr)
|
|
}
|
|
}
|
|
|
|
return obj, closeFunc, nil
|
|
}
|