Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2140 from YvesChan/qmp_race
Browse files Browse the repository at this point in the history
vc/qemu: add mutex to qmp monitor channel in qmpSetup()
  • Loading branch information
jcvenegas authored Nov 8, 2019
2 parents 94b3cf2 + 5b31282 commit d0615f8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"syscall"
"time"
"unsafe"
Expand Down Expand Up @@ -48,6 +49,7 @@ const romFile = ""
const defaultDisableModern = false

type qmpChannel struct {
sync.Mutex
ctx context.Context
path string
qmp *govmmQemu.QMP
Expand Down Expand Up @@ -921,6 +923,9 @@ func (q *qemu) togglePauseSandbox(pause bool) error {
}

func (q *qemu) qmpSetup() error {
q.qmpMonitorCh.Lock()
defer q.qmpMonitorCh.Unlock()

if q.qmpMonitorCh.qmp != nil {
return nil
}
Expand Down Expand Up @@ -949,6 +954,9 @@ func (q *qemu) qmpSetup() error {
}

func (q *qemu) qmpShutdown() {
q.qmpMonitorCh.Lock()
defer q.qmpMonitorCh.Unlock()

if q.qmpMonitorCh.qmp != nil {
q.qmpMonitorCh.qmp.Shutdown()
// wait on disconnected channel to be sure that the qmp channel has
Expand Down

0 comments on commit d0615f8

Please sign in to comment.