all: sync with master

This commit is contained in:
Eugene Burkov
2025-01-20 14:41:16 +03:00
parent ceb178fcd5
commit 2e52a2c8a0
61 changed files with 2533 additions and 2711 deletions

View File

@@ -167,13 +167,13 @@ func setupContext(opts options) (err error) {
if err != nil {
log.Error("parsing configuration file: %s", err)
os.Exit(1)
os.Exit(osutil.ExitCodeFailure)
}
if opts.checkConfig {
log.Info("configuration file is ok")
os.Exit(0)
os.Exit(osutil.ExitCodeSuccess)
}
return nil
@@ -522,18 +522,20 @@ func isUpdateEnabled(ctx context.Context, l *slog.Logger, opts *options, customU
}
}
// initWeb initializes the web module.
// initWeb initializes the web module. upd and baseLogger must not be nil.
func initWeb(
ctx context.Context,
opts options,
clientBuildFS fs.FS,
upd *updater.Updater,
l *slog.Logger,
baseLogger *slog.Logger,
customURL bool,
) (web *webAPI, err error) {
logger := baseLogger.With(slogutil.KeyPrefix, "webapi")
var clientFS fs.FS
if opts.localFrontend {
log.Info("warning: using local frontend files")
logger.WarnContext(ctx, "using local frontend files")
clientFS = os.DirFS("build/static")
} else {
@@ -543,10 +545,12 @@ func initWeb(
}
}
disableUpdate := !isUpdateEnabled(ctx, l, &opts, customURL)
disableUpdate := !isUpdateEnabled(ctx, baseLogger, &opts, customURL)
webConf := &webConfig{
updater: upd,
updater: upd,
logger: logger,
baseLogger: baseLogger,
clientFS: clientFS,
@@ -562,7 +566,7 @@ func initWeb(
serveHTTP3: config.DNS.ServeHTTP3,
}
web = newWebAPI(webConf, l)
web = newWebAPI(ctx, webConf)
if web == nil {
return nil, errors.Error("can not initialize web")
}
@@ -640,7 +644,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
fatalOnError(err)
if config.HTTPConfig.Pprof.Enabled {
startPprof(config.HTTPConfig.Pprof.Port)
startPprof(slogLogger, config.HTTPConfig.Pprof.Port)
}
}
@@ -692,7 +696,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
checkPermissions(ctx, slogLogger, Context.workDir, confPath, dataDir, statsDir, querylogDir)
}
Context.web.start()
Context.web.start(ctx)
// Wait for other goroutines to complete their job.
<-done
@@ -783,7 +787,7 @@ func initUsers() (auth *Auth, err error) {
trustedProxies := netutil.SliceSubnetSet(netutil.UnembedPrefixes(config.DNS.TrustedProxies))
sessionTTL := config.HTTPConfig.SessionTTL.Seconds()
sessionTTL := time.Duration(config.HTTPConfig.SessionTTL).Seconds()
auth = InitAuth(sessFilename, config.Users, uint32(sessionTTL), rateLimiter, trustedProxies)
if auth == nil {
return nil, errors.Error("initializing auth module failed")
@@ -803,15 +807,15 @@ func (c *configuration) anonymizer() (ipmut *aghnet.IPMut) {
return aghnet.NewIPMut(anonFunc)
}
// startMods initializes and starts the DNS server after installation. l must
// not be nil.
func startMods(l *slog.Logger) (err error) {
// startMods initializes and starts the DNS server after installation.
// baseLogger must not be nil.
func startMods(baseLogger *slog.Logger) (err error) {
statsDir, querylogDir, err := checkStatsAndQuerylogDirs(&Context, config)
if err != nil {
return err
}
err = initDNS(l, statsDir, querylogDir)
err = initDNS(baseLogger, statsDir, querylogDir)
if err != nil {
return err
}
@@ -984,7 +988,7 @@ func loadCmdLineOpts() (opts options) {
exitWithError()
}
os.Exit(0)
os.Exit(osutil.ExitCodeSuccess)
}
return opts