diff options
author | Aditya Rajan <arajan@redhat.com> | 2021-09-30 15:45:32 +0530 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2021-10-19 14:01:27 -0400 |
commit | c6be71486d4357cb3cbb380e846e32780fcb37f5 (patch) | |
tree | cc4ae257f3f88bbf0c79f55d2093859c4b49ea36 /pkg | |
parent | 835d74ac63747e4e97b134d57a81679d41295310 (diff) | |
download | podman-c6be71486d4357cb3cbb380e846e32780fcb37f5.tar.gz podman-c6be71486d4357cb3cbb380e846e32780fcb37f5.tar.bz2 podman-c6be71486d4357cb3cbb380e846e32780fcb37f5.zip |
machine: silently cleanup dangling sockets before rm if possible
Try to cleanup dandling pid and machine socket if possible silently
before `rm`.
[NO TESTS NEEDED]
Signed-off-by: Aditya Rajan <arajan@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/machine/qemu/machine.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index d0f48da5f..03197fef1 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -460,6 +460,22 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun for _, msg := range files { confirmationMessage += msg + "\n" } + + // Get path to socket and pidFile before we do any cleanups + qemuSocketFile, pidFile, errSocketFile := v.getSocketandPid() + //silently try to delete socket and pid file + //remove socket and pid file if any: warn at low priority if things fail + if errSocketFile == nil { + // Remove the pidfile + if err := os.Remove(pidFile); err != nil && !errors.Is(err, os.ErrNotExist) { + logrus.Debugf("Error while removing pidfile: %v", err) + } + // Remove socket + if err := os.Remove(qemuSocketFile); err != nil && !errors.Is(err, os.ErrNotExist) { + logrus.Debugf("Error while removing podman-machine-socket: %v", err) + } + } + confirmationMessage += "\n" return confirmationMessage, func() error { for _, f := range files { |