mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
net/dns: fix staticheck.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
d6bb11b5bf
commit
84bd50329a
@ -9,11 +9,8 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -29,46 +26,6 @@ const (
|
|||||||
lowerPriority = int32(200) // lower than all builtin auto priorities
|
lowerPriority = int32(200) // lower than all builtin auto priorities
|
||||||
)
|
)
|
||||||
|
|
||||||
// isNMActive determines if NetworkManager is currently managing system DNS settings.
|
|
||||||
func isNMActive() bool {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
conn, err := dbus.SystemBus()
|
|
||||||
if err != nil {
|
|
||||||
// Probably no DBus on this system. Either way, we can't
|
|
||||||
// control NM without DBus.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to ping NetworkManager's DnsManager object. If it responds,
|
|
||||||
// NM is running and we're allowed to touch it.
|
|
||||||
nm := conn.Object("org.freedesktop.NetworkManager", dbus.ObjectPath("/org/freedesktop/NetworkManager/DnsManager"))
|
|
||||||
call := nm.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", 0)
|
|
||||||
if call.Err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open("/etc/resolv.conf")
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := scanner.Bytes()
|
|
||||||
// Look for the word "NetworkManager" until comments end.
|
|
||||||
if len(line) > 0 && line[0] != '#' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if bytes.Contains(line, []byte("NetworkManager")) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// nmManager uses the NetworkManager DBus API.
|
// nmManager uses the NetworkManager DBus API.
|
||||||
type nmManager struct {
|
type nmManager struct {
|
||||||
interfaceName string
|
interfaceName string
|
||||||
|
@ -5,43 +5,11 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// isResolvconfActive indicates whether the system appears to be using resolvconf.
|
|
||||||
// If this is true, then directManager should be avoided:
|
|
||||||
// resolvconf has exclusive ownership of /etc/resolv.conf.
|
|
||||||
func isResolvconfActive() bool {
|
|
||||||
_, err := exec.LookPath("resolvconf")
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open("/etc/resolv.conf")
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := scanner.Bytes()
|
|
||||||
// Look for the word "resolvconf" until comments end.
|
|
||||||
if len(line) > 0 && line[0] != '#' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if bytes.Contains(line, []byte("resolvconf")) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func newResolvconfManager(logf logger.Logf) (OSConfigurator, error) {
|
func newResolvconfManager(logf logger.Logf) (OSConfigurator, error) {
|
||||||
_, err := exec.Command("resolvconf", "--version").CombinedOutput()
|
_, err := exec.Command("resolvconf", "--version").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user