1
0

Allow access to qemu log while VM is running

This commit is contained in:
dump_stack() 2018-10-06 12:47:09 +00:00
parent 865de3b1a9
commit 335fb038a4

View File

@ -20,7 +20,7 @@ import (
"golang.org/x/crypto/ssh"
)
func readBytesUntilEOF(pipe io.ReadCloser) (buf []byte, err error) {
func readUntilEOF(pipe io.ReadCloser, buf *[]byte) (err error) {
bufSize := 1024
for err != io.EOF {
stdout := make([]byte, bufSize)
@ -31,7 +31,7 @@ func readBytesUntilEOF(pipe io.ReadCloser) (buf []byte, err error) {
return
}
buf = append(buf, stdout[:n]...)
*buf = append(*buf, stdout[:n]...)
}
if err == io.EOF {
@ -40,12 +40,6 @@ func readBytesUntilEOF(pipe io.ReadCloser) (buf []byte, err error) {
return
}
func readUntilEOF(pipe io.ReadCloser) (str string, err error) {
buf, err := readBytesUntilEOF(pipe)
str = string(buf)
return
}
type arch string
const (
@ -87,9 +81,10 @@ type QemuSystem struct {
stdout io.ReadCloser
}
Stdout, Stderr []byte
// accessible after qemu is closed
Stdout, Stderr string
exitErr error
exitErr error
}
// NewQemuSystem constructor
@ -204,9 +199,10 @@ func (q *QemuSystem) Start() (err error) {
return
}
go readUntilEOF(q.pipe.stdout, &q.Stdout)
go readUntilEOF(q.pipe.stderr, &q.Stderr)
go func() {
q.Stdout, _ = readUntilEOF(q.pipe.stdout)
q.Stderr, _ = readUntilEOF(q.pipe.stderr)
q.exitErr = q.cmd.Wait()
q.Died = true
}()
@ -214,7 +210,7 @@ func (q *QemuSystem) Start() (err error) {
time.Sleep(time.Second / 10) // wait for immediately die
if q.Died {
err = errors.New("qemu died immediately: " + q.Stderr)
err = errors.New("qemu died immediately: " + string(q.Stderr))
}
if q.Timeout != 0 {