mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 00:07:16 +00:00
vc/qemu: add mutex to qmp monitor channel in qmpSetup()
Solve possible race condition in qmpSetup() and qmpShutdown() Fixes: #2139 Signed-off-by: Yves Chan <shanks.cyp@gmail.com>
This commit is contained in:
parent
7d484dfe4c
commit
5b31282558
@ -19,6 +19,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -48,6 +49,7 @@ const romFile = ""
|
|||||||
const defaultDisableModern = false
|
const defaultDisableModern = false
|
||||||
|
|
||||||
type qmpChannel struct {
|
type qmpChannel struct {
|
||||||
|
sync.Mutex
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
path string
|
path string
|
||||||
qmp *govmmQemu.QMP
|
qmp *govmmQemu.QMP
|
||||||
@ -921,6 +923,9 @@ func (q *qemu) togglePauseSandbox(pause bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) qmpSetup() error {
|
func (q *qemu) qmpSetup() error {
|
||||||
|
q.qmpMonitorCh.Lock()
|
||||||
|
defer q.qmpMonitorCh.Unlock()
|
||||||
|
|
||||||
if q.qmpMonitorCh.qmp != nil {
|
if q.qmpMonitorCh.qmp != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -949,6 +954,9 @@ func (q *qemu) qmpSetup() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) qmpShutdown() {
|
func (q *qemu) qmpShutdown() {
|
||||||
|
q.qmpMonitorCh.Lock()
|
||||||
|
defer q.qmpMonitorCh.Unlock()
|
||||||
|
|
||||||
if q.qmpMonitorCh.qmp != nil {
|
if q.qmpMonitorCh.qmp != nil {
|
||||||
q.qmpMonitorCh.qmp.Shutdown()
|
q.qmpMonitorCh.qmp.Shutdown()
|
||||||
// wait on disconnected channel to be sure that the qmp channel has
|
// wait on disconnected channel to be sure that the qmp channel has
|
||||||
|
Loading…
Reference in New Issue
Block a user