Merge: -(global): fixing the installation flow on windows

* commit 'abbf8fb87b747700ecced07c9ca0b8e1f997ece1':
  -(global): fixing the installation flow on windows
This commit is contained in:
Andrey Meshkov 2019-12-23 15:21:29 +03:00
commit 87a82f5e60
6 changed files with 30 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"net" "net"
"net/http" "net/http"
"os/exec" "os/exec"
"runtime"
"strconv" "strconv"
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
@ -117,6 +118,10 @@ func handleInstallCheckConfig(w http.ResponseWriter, r *http.Request) {
// Check if DNSStubListener is active // Check if DNSStubListener is active
func checkDNSStubListener() bool { func checkDNSStubListener() bool {
if runtime.GOOS != "linux" {
return false
}
cmd := exec.Command("systemctl", "is-enabled", "systemd-resolved") cmd := exec.Command("systemctl", "is-enabled", "systemd-resolved")
log.Tracef("executing %s %v", cmd.Path, cmd.Args) log.Tracef("executing %s %v", cmd.Path, cmd.Args)
_, err := cmd.Output() _, err := cmd.Output()

View File

@ -242,6 +242,10 @@ func checkPortAvailable(host string, port int) error {
return err return err
} }
ln.Close() 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 return nil
} }
@ -251,6 +255,10 @@ func checkPacketPortAvailable(host string, port int) error {
return err return err
} }
ln.Close() 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 return err
} }

View File

@ -20,6 +20,8 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/isdelve"
"github.com/AdguardTeam/AdGuardHome/dhcpd" "github.com/AdguardTeam/AdGuardHome/dhcpd"
"github.com/AdguardTeam/AdGuardHome/dnsfilter" "github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/AdGuardHome/dnsforward"
@ -284,7 +286,8 @@ func httpServerLoop() {
// and if not, ask and try to run as root // and if not, ask and try to run as root
func requireAdminRights() { func requireAdminRights() {
admin, _ := haveAdminRights() admin, _ := haveAdminRights()
if admin { if //noinspection ALL
admin || isdelve.Enabled {
return return
} }

5
isdelve/delve.go Normal file
View File

@ -0,0 +1,5 @@
// +build delve
package isdelve
const Enabled = true

3
isdelve/doc.go Normal file
View File

@ -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

5
isdelve/nodelve.go Normal file
View File

@ -0,0 +1,5 @@
// +build !delve
package isdelve
const Enabled = false