mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-08 18:05:41 +00:00
pkg/machine: refresh config after we hold lock
Currently we first read the conf and then lock, this is racy because while we wait for the lock another process might change the state so the only way to have the actual current state is to read the file while holding the lock. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
be25514b5f
commit
1dfd3d3d12
1 changed files with 9 additions and 0 deletions
|
|
@ -323,6 +323,9 @@ func Stop(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDef
|
|||
// an error. so putting in one place instead of sprinkling all over.
|
||||
mc.Lock()
|
||||
defer mc.Unlock()
|
||||
if err := mc.Refresh(); err != nil {
|
||||
return fmt.Errorf("reload config: %w", err)
|
||||
}
|
||||
|
||||
return stopLocked(mc, mp, dirs, hardStop)
|
||||
}
|
||||
|
|
@ -377,6 +380,9 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
|
|||
|
||||
mc.Lock()
|
||||
defer mc.Unlock()
|
||||
if err := mc.Refresh(); err != nil {
|
||||
return fmt.Errorf("reload config: %w", err)
|
||||
}
|
||||
|
||||
// Set starting to true
|
||||
mc.Starting = true
|
||||
|
|
@ -538,6 +544,9 @@ func Set(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, opts machineDefin
|
|||
func Remove(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.RemoveOptions) error {
|
||||
mc.Lock()
|
||||
defer mc.Unlock()
|
||||
if err := mc.Refresh(); err != nil {
|
||||
return fmt.Errorf("reload config: %w", err)
|
||||
}
|
||||
|
||||
state, err := mp.State(mc, false)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue