Skip to content

Commit

Permalink
Merge pull request #11342 from baude/machinecleanups
Browse files Browse the repository at this point in the history
clean up socket and pid files from podman machine
  • Loading branch information
mheon authored Aug 30, 2021
2 parents 4834b73 + a2a1663 commit c976667
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/machine/qemu/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
qemuSocketConn net.Conn
wait time.Duration = time.Millisecond * 500
)

if err := v.startHostNetworking(); err != nil {
return errors.Errorf("unable to start host networking: %q", err)
}
Expand All @@ -264,7 +265,11 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
if err != nil {
return err
}

// If the qemusocketpath exists and the vm is off/down, we should rm
// it before the dial as to avoid a segv
if err := os.Remove(qemuSocketPath); err != nil && !errors.Is(err, os.ErrNotExist) {
logrus.Warn(err)
}
for i := 0; i < 6; i++ {
qemuSocketConn, err = net.Dial("unix", qemuSocketPath)
if err == nil {
Expand Down Expand Up @@ -352,7 +357,7 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
if _, err = qmpMonitor.Run(input); err != nil {
return err
}
_, pidFile, err := v.getSocketandPid()
qemuSocketFile, pidFile, err := v.getSocketandPid()
if err != nil {
return err
}
Expand All @@ -373,7 +378,16 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
if p == nil && err != nil {
return err
}
return p.Kill()
// Kill the process
if err := p.Kill(); err != nil {
return err
}
// Remove the pidfile
if err := os.Remove(pidFile); err != nil && !errors.Is(err, os.ErrNotExist) {
logrus.Warn(err)
}
// Remove socket
return os.Remove(qemuSocketFile)
}

// NewQMPMonitor creates the monitor subsection of our vm
Expand Down

0 comments on commit c976667

Please sign in to comment.