home: fix client storage panic

This commit is contained in:
Stanislav Chzhen 2024-10-03 17:55:39 +03:00
parent b32b8f9c7e
commit e7f34cc435
2 changed files with 11 additions and 11 deletions

View File

@ -92,9 +92,9 @@ func (clients *clientsContainer) Init(
// TODO(e.burkov): The option should probably be returned, since hosts file // TODO(e.burkov): The option should probably be returned, since hosts file
// currently used not only for clients' information enrichment, but also in // currently used not only for clients' information enrichment, but also in
// the filtering module and upstream addresses resolution. // the filtering module and upstream addresses resolution.
var hosts client.HostsContainer = etcHosts var hosts client.HostsContainer
if !config.Clients.Sources.HostsFile { if config.Clients.Sources.HostsFile && etcHosts != nil {
hosts = nil hosts = etcHosts
} }
clients.storage, err = client.NewStorage(&client.StorageConfig{ clients.storage, err = client.NewStorage(&client.StorageConfig{

View File

@ -148,6 +148,14 @@ func setupContext(opts options) (err error) {
Context.tlsRoots = aghtls.SystemRootCAs() Context.tlsRoots = aghtls.SystemRootCAs()
Context.mux = http.NewServeMux() Context.mux = http.NewServeMux()
if !opts.noEtcHosts {
err = setupHostsContainer()
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return err
}
}
if Context.firstRun { if Context.firstRun {
log.Info("This is the first time AdGuard Home is launched") log.Info("This is the first time AdGuard Home is launched")
checkPermissions() checkPermissions()
@ -168,14 +176,6 @@ func setupContext(opts options) (err error) {
os.Exit(0) os.Exit(0)
} }
if !opts.noEtcHosts {
err = setupHostsContainer()
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return err
}
}
return nil return nil
} }