From 88469d4aaa3eff427bd5a719a3132dbedfabcc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 23 Aug 2022 23:22:49 +0800 Subject: [PATCH] Check configuration before reload --- cmd/sing-box/cmd_run.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/sing-box/cmd_run.go b/cmd/sing-box/cmd_run.go index 62679510..6298387d 100644 --- a/cmd/sing-box/cmd_run.go +++ b/cmd/sing-box/cmd_run.go @@ -79,19 +79,29 @@ func create() (*box.Box, context.CancelFunc, error) { } func run() error { + osSignals := make(chan os.Signal, 1) + signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) for { instance, cancel, err := create() if err != nil { return err } runtimeDebug.FreeOSMemory() - osSignals := make(chan os.Signal, 1) - signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) - osSignal := <-osSignals - cancel() - instance.Close() - if osSignal != syscall.SIGHUP { - return nil + for { + osSignal := <-osSignals + if osSignal == syscall.SIGHUP { + err = check() + if err != nil { + log.Error(E.Cause(err, "reload service")) + continue + } + } + cancel() + instance.Close() + if osSignal != syscall.SIGHUP { + return nil + } + break } } }