From a528ed9f947d42f4324cd4f2263a015d34d7341f Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Wed, 17 Oct 2018 20:43:26 +0300 Subject: [PATCH] Stop requiring current working directory to be the location of AdGuardHome. Fixes #381. --- config.go | 4 +++- coredns.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 34b5a95b..09e89ee1 100644 --- a/config.go +++ b/config.go @@ -195,8 +195,10 @@ func generateCoreDNSConfigText() (string, error) { } var configBytes bytes.Buffer + temporaryConfig := config.CoreDNS + temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) // run the template - err = t.Execute(&configBytes, config.CoreDNS) + err = t.Execute(&configBytes, &temporaryConfig) if err != nil { log.Printf("Couldn't generate DNS config: %s", err) return "", err diff --git a/coredns.go b/coredns.go index fe3415a2..b6941f2b 100644 --- a/coredns.go +++ b/coredns.go @@ -3,10 +3,13 @@ package main import ( "fmt" "log" - "sync" + "os" + "path/filepath" + "sync" // Include all plugins. - // Include all plugins. _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin" + "github.com/coredns/coredns/core/dnsserver" + "github.com/coredns/coredns/coremain" _ "github.com/coredns/coredns/plugin/auto" _ "github.com/coredns/coredns/plugin/autopath" _ "github.com/coredns/coredns/plugin/bind" @@ -37,9 +40,6 @@ import ( _ "github.com/coredns/coredns/plugin/tls" _ "github.com/coredns/coredns/plugin/whoami" _ "github.com/mholt/caddy/onevent" - - "github.com/coredns/coredns/core/dnsserver" - "github.com/coredns/coredns/coremain" ) // Directives are registered in the order they should be @@ -109,6 +109,11 @@ func startDNSServer() error { isCoreDNSRunning = true isCoreDNSRunningLock.Unlock() + configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile) + os.Args = os.Args[:1] + os.Args = append(os.Args, "-conf") + os.Args = append(os.Args, configpath) + err := writeCoreDNSConfig() if err != nil { errortext := fmt.Errorf("Unable to write coredns config: %s", err)