mirror of
https://github.com/containers/podman.git
synced 2025-07-02 08:47:43 +08:00
Merge pull request #22278 from mheon/error_on_unhandled_reboot
Detect unhandled reboots and require user intervention
This commit is contained in:
@ -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
|
||||
|
@ -4,3 +4,7 @@ package libpod
|
||||
|
||||
func checkCgroups2UnifiedMode(runtime *Runtime) {
|
||||
}
|
||||
|
||||
func (r *Runtime) checkBootID(runtimeAliveFile string) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user