diff --git a/cmd/sing-box/cmd.go b/cmd/sing-box/cmd.go index 9ae3a268..a2d4a00b 100644 --- a/cmd/sing-box/cmd.go +++ b/cmd/sing-box/cmd.go @@ -67,5 +67,5 @@ func preRun(cmd *cobra.Command, args []string) { if len(configPaths) == 0 && len(configDirectories) == 0 { configPaths = append(configPaths, "config.json") } - globalCtx = service.ContextWith(globalCtx, deprecated.NewEnvManager(log.StdLogger())) + globalCtx = service.ContextWith(globalCtx, deprecated.NewStderrManager(log.StdLogger())) } diff --git a/cmd/sing-box/cmd_check.go b/cmd/sing-box/cmd_check.go index 1beab954..29a39081 100644 --- a/cmd/sing-box/cmd_check.go +++ b/cmd/sing-box/cmd_check.go @@ -30,7 +30,7 @@ func check() error { if err != nil { return err } - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(globalCtx) instance, err := box.New(box.Options{ Context: ctx, Options: options, diff --git a/experimental/deprecated/env.go b/experimental/deprecated/stderr.go similarity index 59% rename from experimental/deprecated/env.go rename to experimental/deprecated/stderr.go index 113b8717..0826baf9 100644 --- a/experimental/deprecated/env.go +++ b/experimental/deprecated/stderr.go @@ -7,15 +7,23 @@ import ( "github.com/sagernet/sing/common/logger" ) -type envManager struct { - logger logger.Logger +type stderrManager struct { + logger logger.Logger + reported map[string]bool } -func NewEnvManager(logger logger.Logger) Manager { - return &envManager{logger: logger} +func NewStderrManager(logger logger.Logger) Manager { + return &stderrManager{ + logger: logger, + reported: make(map[string]bool), + } } -func (f *envManager) ReportDeprecated(feature Note) { +func (f *stderrManager) ReportDeprecated(feature Note) { + if f.reported[feature.Name] { + return + } + f.reported[feature.Name] = true if !feature.Impending() { f.logger.Warn(feature.MessageWithLink()) return diff --git a/experimental/libbox/deprecated.go b/experimental/libbox/deprecated.go index b953014f..f85b7747 100644 --- a/experimental/libbox/deprecated.go +++ b/experimental/libbox/deprecated.go @@ -4,27 +4,28 @@ import ( "sync" "github.com/sagernet/sing-box/experimental/deprecated" + "github.com/sagernet/sing/common" ) var _ deprecated.Manager = (*deprecatedManager)(nil) type deprecatedManager struct { - access sync.Mutex - features []deprecated.Note + access sync.Mutex + notes []deprecated.Note } func (m *deprecatedManager) ReportDeprecated(feature deprecated.Note) { m.access.Lock() defer m.access.Unlock() - m.features = append(m.features, feature) + m.notes = common.Uniq(append(m.notes, feature)) } func (m *deprecatedManager) Get() []deprecated.Note { m.access.Lock() defer m.access.Unlock() - features := m.features - m.features = nil - return features + notes := m.notes + m.notes = nil + return notes } var _ = deprecated.Note(DeprecatedNote{})