1
0

Add stdout trace for qemu ssh commands

This commit is contained in:
dump_stack() 2023-04-06 18:20:55 +00:00
parent 5ce73d2fc5
commit bbd6f79443
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

@ -5,6 +5,7 @@
package qemu package qemu
import ( import (
"bufio"
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
@ -343,8 +344,13 @@ func (q System) ssh(user string) (client *ssh.Client, err error) {
// Command executes shell commands on qemu system // Command executes shell commands on qemu system
func (q System) Command(user, cmd string) (output string, err error) { func (q System) Command(user, cmd string) (output string, err error) {
log.Debug().Str("kernel", q.kernel.KernelPath). flog := log.With().
Str("user", user).Str("cmd", cmd).Msg("qemu command") Str("kernel", q.kernel.KernelPath).
Str("user", user).
Str("cmd", cmd).
Logger()
flog.Debug().Msg("qemu command")
client, err := q.ssh(user) client, err := q.ssh(user)
if err != nil { if err != nil {
@ -357,8 +363,27 @@ func (q System) Command(user, cmd string) (output string, err error) {
return return
} }
bytesOutput, err := session.CombinedOutput(cmd) stdout, err := session.StdoutPipe()
output = string(bytesOutput) if err != nil {
return
}
session.Stderr = session.Stdout
err = session.Start(cmd)
if err != nil {
return
}
go func() {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
m := scanner.Text()
output += m + "\n"
flog.Trace().Str("stdout", m).Msg("")
}
}()
err = session.Wait()
return return
} }