From abbf8fb87b747700ecced07c9ca0b8e1f997ece1 Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Mon, 23 Dec 2019 14:57:10 +0300 Subject: [PATCH] -(global): fixing the installation flow on windows There could be a bug caused by the lack of SO_REUSEPORT --- home/control_install.go | 5 +++++ home/helpers.go | 8 ++++++++ home/home.go | 5 ++++- isdelve/delve.go | 5 +++++ isdelve/doc.go | 3 +++ isdelve/nodelve.go | 5 +++++ 6 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 isdelve/delve.go create mode 100644 isdelve/doc.go create mode 100644 isdelve/nodelve.go diff --git a/home/control_install.go b/home/control_install.go index 61abeb19..9d13ec74 100644 --- a/home/control_install.go +++ b/home/control_install.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "os/exec" + "runtime" "strconv" "github.com/AdguardTeam/golibs/log" @@ -117,6 +118,10 @@ func handleInstallCheckConfig(w http.ResponseWriter, r *http.Request) { // Check if DNSStubListener is active func checkDNSStubListener() bool { + if runtime.GOOS != "linux" { + return false + } + cmd := exec.Command("systemctl", "is-enabled", "systemd-resolved") log.Tracef("executing %s %v", cmd.Path, cmd.Args) _, err := cmd.Output() diff --git a/home/helpers.go b/home/helpers.go index 2fdd0181..c00fcbc8 100644 --- a/home/helpers.go +++ b/home/helpers.go @@ -242,6 +242,10 @@ func checkPortAvailable(host string, port int) error { return err } ln.Close() + + // It seems that net.Listener.Close() doesn't close file descriptors right away. + // We wait for some time and hope that this fd will be closed. + time.Sleep(100 * time.Millisecond) return nil } @@ -251,6 +255,10 @@ func checkPacketPortAvailable(host string, port int) error { return err } ln.Close() + + // It seems that net.Listener.Close() doesn't close file descriptors right away. + // We wait for some time and hope that this fd will be closed. + time.Sleep(100 * time.Millisecond) return err } diff --git a/home/home.go b/home/home.go index 9315ca0b..fcefa4b6 100644 --- a/home/home.go +++ b/home/home.go @@ -20,6 +20,8 @@ import ( "syscall" "time" + "github.com/AdguardTeam/AdGuardHome/isdelve" + "github.com/AdguardTeam/AdGuardHome/dhcpd" "github.com/AdguardTeam/AdGuardHome/dnsfilter" "github.com/AdguardTeam/AdGuardHome/dnsforward" @@ -284,7 +286,8 @@ func httpServerLoop() { // and if not, ask and try to run as root func requireAdminRights() { admin, _ := haveAdminRights() - if admin { + if //noinspection ALL + admin || isdelve.Enabled { return } diff --git a/isdelve/delve.go b/isdelve/delve.go new file mode 100644 index 00000000..bc9a647e --- /dev/null +++ b/isdelve/delve.go @@ -0,0 +1,5 @@ +// +build delve + +package isdelve + +const Enabled = true diff --git a/isdelve/doc.go b/isdelve/doc.go new file mode 100644 index 00000000..862b10d0 --- /dev/null +++ b/isdelve/doc.go @@ -0,0 +1,3 @@ +// Package isdelve is for checking if we're debugging: +// https://stackoverflow.com/questions/47879070/how-can-i-see-if-the-goland-debugger-is-running-in-the-program +package isdelve diff --git a/isdelve/nodelve.go b/isdelve/nodelve.go new file mode 100644 index 00000000..2b06a17c --- /dev/null +++ b/isdelve/nodelve.go @@ -0,0 +1,5 @@ +// +build !delve + +package isdelve + +const Enabled = false