diff --git a/experimental/boxdd/cmd_run.go b/experimental/boxdd/cmd_run.go index ea58b3b0..be5452b8 100644 --- a/experimental/boxdd/cmd_run.go +++ b/experimental/boxdd/cmd_run.go @@ -6,6 +6,7 @@ import ( "path/filepath" "syscall" + C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/experimental/libbox" "github.com/sagernet/sing-box/log" E "github.com/sagernet/sing/common/exceptions" @@ -60,6 +61,7 @@ func prepareWorkingDirectory() error { WorkingPath: workingDirectory, TempPath: workingDirectory, CrashReportSource: "Daemon", + AppVersion: C.Version, }) if err != nil { return err diff --git a/experimental/boxdd/server.go b/experimental/boxdd/server.go index e7e03cdb..583a25b5 100644 --- a/experimental/boxdd/server.go +++ b/experimental/boxdd/server.go @@ -10,6 +10,7 @@ import ( "sync" "github.com/sagernet/sing-box/adapter" + C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/daemon" "github.com/sagernet/sing-box/experimental/libbox" "github.com/sagernet/sing-box/include" @@ -194,6 +195,7 @@ func (d *Daemon) configureWorkingDirectoryLocked(directory string) error { WorkingPath: directory, TempPath: directory, CrashReportSource: "Daemon", + AppVersion: C.Version, }) if err != nil { return err diff --git a/experimental/libbox/oom_report.go b/experimental/libbox/oom_report.go index 01421b47..d9bbbdd5 100644 --- a/experimental/libbox/oom_report.go +++ b/experimental/libbox/oom_report.go @@ -357,6 +357,17 @@ func promoteOOMDraftAt(workingPath string) { if err != nil || !info.IsDir() { return } + metadataContent, err := os.ReadFile(filepath.Join(draftPath, "metadata.json")) + if err != nil { + os.RemoveAll(draftPath) + return + } + var draftMetadata reportMetadata + err = json.Unmarshal(metadataContent, &draftMetadata) + if err != nil || draftMetadata.AppVersion != sAppVersion || draftMetadata.AppMarketingVersion != sAppMarketingVersion { + os.RemoveAll(draftPath) + return + } reportsDir := filepath.Join(workingPath, "oom_reports") initReportDir(reportsDir) destPath, err := nextAvailableReportPath(reportsDir, info.ModTime().UTC()) diff --git a/experimental/libbox/report.go b/experimental/libbox/report.go index 816dcac4..fc41f506 100644 --- a/experimental/libbox/report.go +++ b/experimental/libbox/report.go @@ -34,11 +34,13 @@ func baseReportMetadata() reportMetadata { processName = "" } return reportMetadata{ - Source: sCrashReportSource, - ProcessName: processName, - ProcessPath: processPath, - CoreVersion: C.Version, - GoVersion: GoVersion(), + Source: sCrashReportSource, + ProcessName: processName, + ProcessPath: processPath, + AppVersion: sAppVersion, + AppMarketingVersion: sAppMarketingVersion, + CoreVersion: C.Version, + GoVersion: GoVersion(), } } diff --git a/experimental/libbox/setup.go b/experimental/libbox/setup.go index c12d8771..22cf6e14 100644 --- a/experimental/libbox/setup.go +++ b/experimental/libbox/setup.go @@ -31,6 +31,8 @@ var ( sLogMaxLines int sDebug bool sCrashReportSource string + sAppVersion string + sAppMarketingVersion string sOOMKillerEnabled bool sOOMKillerDisabled bool sOOMMemoryLimit int64 @@ -52,6 +54,8 @@ type SetupOptions struct { LogMaxLines int Debug bool CrashReportSource string + AppVersion string + AppMarketingVersion string OomKillerEnabled bool OomKillerDisabled bool OomMemoryLimit int64 @@ -75,6 +79,8 @@ func applySetupOptions(options *SetupOptions) { sLogMaxLines = options.LogMaxLines sDebug = options.Debug sCrashReportSource = options.CrashReportSource + sAppVersion = options.AppVersion + sAppMarketingVersion = options.AppMarketingVersion ReloadSetupOptions(options) }