From 1f93cffd5acaed16bcac7b16aa9a79cbeb4fdd4d Mon Sep 17 00:00:00 2001 From: lifupan Date: Mon, 16 Sep 2019 09:27:06 +0800 Subject: [PATCH] virtcontainers: fix the issue of missing qemu error logs When 'debug' is enabled, qemu's debug info is output into qemu's log file. When lauching qemu failed, it's better to log these debug info and return it directly for debugging. Fixes:#2042 Signed-off-by: lifupan --- virtcontainers/qemu.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index ae33f846f4..c8c0bb8790 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -763,7 +763,15 @@ func (q *qemu) startSandbox(timeout int) error { var strErr string strErr, err = govmmQemu.LaunchQemu(q.qemuConfig, newQMPLogger()) if err != nil { - return fmt.Errorf("fail to launch qemu: %s, error messages from qemu log: %s", err, strErr) + if q.config.Debug && q.qemuConfig.LogFile != "" { + b, err := ioutil.ReadFile(q.qemuConfig.LogFile) + if err == nil { + strErr += string(b) + } + } + + q.Logger().WithError(err).Errorf("failed to launch qemu: %s", strErr) + return fmt.Errorf("failed to launch qemu: %s, error messages from qemu log: %s", err, strErr) } err = q.waitSandbox(timeout) // the virtiofsd deferred checks err's value