diff --git a/experimental/boxdd/server.go b/experimental/boxdd/server.go index cb195e01..ad9df8a2 100644 --- a/experimental/boxdd/server.go +++ b/experimental/boxdd/server.go @@ -223,7 +223,7 @@ func (d *Daemon) startServiceLocked(ctx context.Context, ownerUserID string, con }) d.startedService.SetOOMKillerOptions(options.OOMKillerEnabled, options.OOMKillerDisabled, uint64(options.OOMMemoryLimit)) if options.PowerReportEnabled { - err = d.powerManager.Start(libbox.PowerReportOptions(d.startedService, nil)) + err = d.powerManager.Start(libbox.PowerReportOptions(d.startedService)) if err != nil { d.logger.Warn("start power report recorder: ", err) } diff --git a/experimental/libbox/log.go b/experimental/libbox/log.go index 49a0e07a..992cf8f5 100644 --- a/experimental/libbox/log.go +++ b/experimental/libbox/log.go @@ -48,6 +48,10 @@ func archiveCrashReport(path string, crashReportsDir string) { reportMetadata: baseReportMetadata(), CrashedAt: crashTime.Format(time.RFC3339), } + platformSnapshot := readPlatformSnapshot() + if platformSnapshot != nil { + metadata.Platform = platformSnapshot + } writeReportMetadata(destPath, metadata) os.Remove(path) copyConfigSnapshot(destPath) diff --git a/experimental/libbox/power_report.go b/experimental/libbox/power_report.go index cad04136..2d90c62a 100644 --- a/experimental/libbox/power_report.go +++ b/experimental/libbox/power_report.go @@ -13,19 +13,14 @@ import ( type powerReportMetadata struct { reportMetadata - StartedAt string `json:"startedAt"` - IncludeAllNetworks *bool `json:"includeAllNetworks,omitempty"` + StartedAt string `json:"startedAt"` } -func PowerReportOptions(startedService *daemon.StartedService, platformInterface PlatformInterface) powerreport.Options { +func PowerReportOptions(startedService *daemon.StartedService) powerreport.Options { metadata := powerReportMetadata{ reportMetadata: baseReportMetadata(), StartedAt: time.Now().UTC().Format(time.RFC3339), } - if platformInterface != nil && platformInterface.UnderNetworkExtension() { - includeAllNetworks := platformInterface.IncludeAllNetworks() - metadata.IncludeAllNetworks = &includeAllNetworks - } return powerreport.Options{ BasePath: sWorkingPath, Logger: log.StdLogger(), diff --git a/experimental/libbox/report.go b/experimental/libbox/report.go index fc41f506..ff5e0f4f 100644 --- a/experimental/libbox/report.go +++ b/experimental/libbox/report.go @@ -16,15 +16,16 @@ import ( ) type reportMetadata struct { - Source string `json:"source,omitempty"` - BundleIdentifier string `json:"bundleIdentifier,omitempty"` - ProcessName string `json:"processName,omitempty"` - ProcessPath string `json:"processPath,omitempty"` - StartedAt string `json:"startedAt,omitempty"` - AppVersion string `json:"appVersion,omitempty"` - AppMarketingVersion string `json:"appMarketingVersion,omitempty"` - CoreVersion string `json:"coreVersion,omitempty"` - GoVersion string `json:"goVersion,omitempty"` + Source string `json:"source,omitempty"` + BundleIdentifier string `json:"bundleIdentifier,omitempty"` + ProcessName string `json:"processName,omitempty"` + ProcessPath string `json:"processPath,omitempty"` + StartedAt string `json:"startedAt,omitempty"` + AppVersion string `json:"appVersion,omitempty"` + AppMarketingVersion string `json:"appMarketingVersion,omitempty"` + CoreVersion string `json:"coreVersion,omitempty"` + GoVersion string `json:"goVersion,omitempty"` + Platform json.RawMessage `json:"platform,omitempty"` } func baseReportMetadata() reportMetadata { @@ -41,6 +42,7 @@ func baseReportMetadata() reportMetadata { AppMarketingVersion: sAppMarketingVersion, CoreVersion: C.Version, GoVersion: GoVersion(), + Platform: sPlatformMetadata, } } @@ -70,6 +72,28 @@ func copyConfigSnapshot(destPath string) { writeReportFile(destPath, "configuration.json", content) } +func platformSnapshotPath() string { + return filepath.Join(sWorkingPath, "PlatformMetadata-"+sCrashReportSource+".json") +} + +func savePlatformSnapshot() { + snapshotPath := platformSnapshotPath() + if sPlatformMetadata == nil { + os.Remove(snapshotPath) + return + } + os.WriteFile(snapshotPath, sPlatformMetadata, 0o666) + chownReport(snapshotPath) +} + +func readPlatformSnapshot() json.RawMessage { + content, err := os.ReadFile(platformSnapshotPath()) + if err != nil || !json.Valid(content) { + return nil + } + return content +} + func initReportDir(path string) { os.MkdirAll(path, 0o777) chownReport(path) diff --git a/experimental/libbox/setup.go b/experimental/libbox/setup.go index a78cba54..07f16734 100644 --- a/experimental/libbox/setup.go +++ b/experimental/libbox/setup.go @@ -1,6 +1,7 @@ package libbox import ( + "encoding/json" "math" "os" "path/filepath" @@ -37,6 +38,7 @@ var ( sOOMKillerDisabled bool sOOMMemoryLimit int64 sPowerReportEnabled bool + sPlatformMetadata []byte ) func init() { @@ -60,6 +62,7 @@ type SetupOptions struct { OomKillerDisabled bool OomMemoryLimit int64 PowerReportEnabled bool + PlatformMetadata string } func applySetupOptions(options *SetupOptions) { @@ -89,6 +92,11 @@ func ReloadSetupOptions(options *SetupOptions) { sOOMKillerDisabled = options.OomKillerDisabled sOOMMemoryLimit = options.OomMemoryLimit sPowerReportEnabled = options.PowerReportEnabled + if json.Valid([]byte(options.PlatformMetadata)) { + sPlatformMetadata = []byte(options.PlatformMetadata) + } else { + sPlatformMetadata = nil + } if sOOMKillerEnabled { if sOOMMemoryLimit == 0 && C.IsIos { sOOMMemoryLimit = oomkiller.DefaultAppleNetworkExtensionMemoryLimit @@ -108,7 +116,9 @@ func Setup(options *SetupOptions) error { applySetupOptions(options) os.MkdirAll(sWorkingPath, 0o777) os.MkdirAll(sTempPath, 0o777) - return redirectStderr(filepath.Join(sWorkingPath, "CrashReport-"+sCrashReportSource+".log")) + err := redirectStderr(filepath.Join(sWorkingPath, "CrashReport-"+sCrashReportSource+".log")) + savePlatformSnapshot() + return err } func SetLocale(localeID string) error {