From 7307c51d6fd8b302b655671daf9611f21b17d8a7 Mon Sep 17 00:00:00 2001 From: Alison Winters Date: Wed, 30 Oct 2019 21:34:00 +0800 Subject: [PATCH] move ConfigLoad into Start function when running as a service (take 2) --- dnscrypt-proxy/main.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index b3dc3f03..50613b43 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -25,6 +25,7 @@ type App struct { wg sync.WaitGroup quit chan struct{} proxy *Proxy + flags *ConfigFlags } func main() { @@ -70,7 +71,8 @@ func main() { } app := &App{ - quit: make(chan struct{}), + quit: make(chan struct{}), + flags: &flags, } svc, err := service.New(app, svcConfig) if err != nil { @@ -79,9 +81,6 @@ func main() { } app.proxy = NewProxy() _ = ServiceManagerStartNotify() - if err := ConfigLoad(app.proxy, &flags); err != nil { - dlog.Fatal(err) - } if len(*svcFlag) != 0 { if svc == nil { dlog.Fatal("Built-in service installation is not supported on this platform") @@ -108,6 +107,9 @@ func main() { dlog.Fatal(err) } } else { + if err := ConfigLoad(app.proxy, &flags); err != nil { + dlog.Fatal(err) + } app.signalWatch() app.Start(nil) } @@ -116,10 +118,15 @@ func main() { } func (app *App) Start(service service.Service) error { - if err := app.proxy.InitPluginsGlobals(); err != nil { - dlog.Fatal(err) - } - go app.appMain() + go func() { + if err := ConfigLoad(app.proxy, app.flags); err != nil { + dlog.Fatal(err) + } + if err := app.proxy.InitPluginsGlobals(); err != nil { + dlog.Fatal(err) + } + app.appMain() + }() return nil }