Merge pull request #22278 from mheon/error_on_unhandled_reboot

Detect unhandled reboots and require user intervention
This commit is contained in:
openshift-merge-bot[bot]
2024-04-05 15:40:42 +00:00
committed by GitHub
3 changed files with 31 additions and 0 deletions

View File

@ -624,6 +624,11 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
}
}
// Check current boot ID - will be written to the alive file.
if err := runtime.checkBootID(runtimeAliveFile); err != nil {
return err
}
runtime.startWorker()
return nil

View File

@ -4,3 +4,7 @@ package libpod
func checkCgroups2UnifiedMode(runtime *Runtime) {
}
func (r *Runtime) checkBootID(runtimeAliveFile string) error {
return nil
}

View File

@ -43,3 +43,25 @@ func checkCgroups2UnifiedMode(runtime *Runtime) {
}
}
}
// Check the current boot ID against the ID cached in the runtime alive file.
func (r *Runtime) checkBootID(runtimeAliveFile string) error {
systemBootID, err := os.ReadFile("/proc/sys/kernel/random/boot_id")
if err == nil {
podmanBootID, err := os.ReadFile(runtimeAliveFile)
if err != nil {
return fmt.Errorf("reading boot ID from runtime alive file: %w", err)
}
if len(podmanBootID) != 0 {
if string(systemBootID) != string(podmanBootID) {
return fmt.Errorf("current system boot ID differs from cached boot ID; an unhandled reboot has occurred. Please delete directories %q and %q and re-run Podman", r.storageConfig.RunRoot, r.config.Engine.TmpDir)
}
} else {
// Write the current boot ID to the alive file.
if err := os.WriteFile(runtimeAliveFile, systemBootID, 0644); err != nil {
return fmt.Errorf("writing boot ID to runtime alive file: %w", err)
}
}
}
return nil
}