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

Commit

Permalink
qemu: add logfile when debug is on
Browse files Browse the repository at this point in the history
So that we can check qemu log to see if something goes wrong.

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Aug 16, 2019
1 parent aebc496 commit e7457e6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ func (q *qemu) startSandbox(timeout int) error {
if err != nil {
return err
}
// append logfile only on debug
if q.config.Debug {
q.qemuConfig.LogFile = filepath.Join(vmPath, "qemu.log")
}

defer func() {
if err != nil {
if err := os.RemoveAll(vmPath); err != nil {
Expand Down Expand Up @@ -850,6 +855,19 @@ func (q *qemu) stopSandbox() error {
q.stopped = true
}()

if q.config.Debug && q.qemuConfig.LogFile != "" {
f, err := os.OpenFile(q.qemuConfig.LogFile, os.O_RDONLY, 0)
if err == nil {
scanner := bufio.NewScanner(f)
for scanner.Scan() {
q.Logger().Debug(scanner.Text())
}
if err := scanner.Err(); err != nil {
q.Logger().WithError(err).Debug("read qemu log failed")
}
}
}

err := q.qmpSetup()
if err != nil {
return err
Expand Down

0 comments on commit e7457e6

Please sign in to comment.