net/dns: avoid Linux PolicyKit GUI dialog during tests

Fixes #2672

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/2687/head
Brad Fitzpatrick 3 years ago
parent edb338f542
commit 36ffd509de

@ -259,7 +259,7 @@ func (m directManager) SetDNS(config OSConfig) error {
// try to manage DNS through resolved when it's around, but as a
// best-effort fallback if we messed up the detection, try to
// restart resolved to make the system configuration consistent.
if isResolvedRunning() {
if isResolvedRunning() && !runningAsGUIDesktopUser() {
exec.Command("systemctl", "restart", "systemd-resolved.service").Run()
}
@ -319,7 +319,7 @@ func (m directManager) Close() error {
return err
}
if isResolvedRunning() {
if isResolvedRunning() && !runningAsGUIDesktopUser() {
exec.Command("systemctl", "restart", "systemd-resolved.service").Run() // Best-effort.
}
@ -385,3 +385,12 @@ func (fs directFS) ReadFile(name string) ([]byte, error) {
func (fs directFS) WriteFile(name string, contents []byte, perm os.FileMode) error {
return ioutil.WriteFile(fs.path(name), contents, perm)
}
// runningAsGUIDesktopUser reports whether it seems that this code is
// being run as a regular user on a Linux desktop. This is a quick
// hack to fix Issue 2672 where PolicyKit pops up a GUI dialog asking
// to proceed we do a best effort attempt to restart
// systemd-resolved.service. There's surely a better way.
func runningAsGUIDesktopUser() bool {
return os.Getuid() != 0 && os.Getenv("DISPLAY") != ""
}

Loading…
Cancel
Save