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

Commit

Permalink
vc/qemu: add mutex to qmp monitor channel in qmpSetup()
Browse files Browse the repository at this point in the history
Solve possible race condition in qmpSetup() and qmpShutdown()

Fixes: #2139

Signed-off-by: Yves Chan <[email protected]>
  • Loading branch information
YvesChan committed Nov 6, 2019
1 parent 7d484df commit 5b31282
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 5b31282

Please sign in to comment.