From 642d6829982e299ff5e9b764a5494b9c6668ac5e Mon Sep 17 00:00:00 2001 From: Aditya Rajan Date: Thu, 30 Sep 2021 15:45:32 +0530 Subject: 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 --- pkg/machine/qemu/machine.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'pkg') diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 09078fbfb..d64dec07b 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 { -- cgit v1.2.3-54-g00ecf