Add debug logs for exec.Command
This commit is contained in:
parent
305c6972ca
commit
08beba2bab
@ -17,6 +17,7 @@ import (
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
"code.dumpstack.io/tools/out-of-tree/qemu"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type ImageCmd struct {
|
||||
@ -146,6 +147,8 @@ func unpackTar(archive, destination string) (err error) {
|
||||
cmd := exec.Command("tar", "-Sxf", archive)
|
||||
cmd.Dir = destination + "/"
|
||||
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%v: %s", err, rawOutput)
|
||||
|
26
kernel.go
26
kernel.go
@ -99,6 +99,8 @@ func (cmd *KernelDockerRegenCmd) Run(kernelCmd *KernelCmd, g *Globals) (err erro
|
||||
args = append(args, "-t", d.ContainerName, imagePath)
|
||||
|
||||
cmd := exec.Command("docker", args...)
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
var rawOutput []byte
|
||||
rawOutput, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
@ -244,6 +246,8 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
|
||||
d := "# BASE\n"
|
||||
|
||||
cmd := exec.Command("docker", "images", "-q", sk.DockerName())
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return
|
||||
@ -349,6 +353,8 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
|
||||
args = append(args, "-t", sk.DockerName(), imagePath)
|
||||
|
||||
cmd = exec.Command("docker", args...)
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Printf("Base image for %s:%s generating error, see log",
|
||||
@ -419,6 +425,8 @@ func dockerImageAppend(sk config.KernelMask, pkgname string) (err error) {
|
||||
args = append(args, "-t", sk.DockerName(), imagePath)
|
||||
|
||||
cmd := exec.Command("docker", args...)
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
// Fallback to previous state
|
||||
@ -441,12 +449,16 @@ func dockerImageAppend(sk config.KernelMask, pkgname string) (err error) {
|
||||
|
||||
func kickImage(name string) (err error) {
|
||||
cmd := exec.Command("docker", "run", name, "bash", "-c", "ls")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
_, err = cmd.CombinedOutput()
|
||||
return
|
||||
}
|
||||
|
||||
func copyKernels(name string) (err error) {
|
||||
cmd := exec.Command("docker", "ps", "-a")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(rawOutput))
|
||||
@ -463,7 +475,9 @@ func copyKernels(name string) (err error) {
|
||||
what := r.FindAll(rawOutput, -1)
|
||||
for _, w := range what {
|
||||
containerID = strings.Fields(string(w))[0]
|
||||
_, err = exec.Command("which", "podman").CombinedOutput()
|
||||
cmd = exec.Command("which", "podman")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
_, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
@ -480,6 +494,8 @@ func copyKernels(name string) (err error) {
|
||||
}
|
||||
|
||||
cmd = exec.Command("docker", "cp", containerID+":/boot/.", target)
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(rawOutput))
|
||||
@ -487,6 +503,8 @@ func copyKernels(name string) (err error) {
|
||||
}
|
||||
|
||||
cmd = exec.Command("docker", "cp", containerID+":/lib/modules", target)
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(rawOutput))
|
||||
@ -494,6 +512,8 @@ func copyKernels(name string) (err error) {
|
||||
}
|
||||
|
||||
cmd = exec.Command("find", target+"modules", "-type", "l", "-delete")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(rawOutput))
|
||||
@ -555,6 +575,8 @@ type dockerImageInfo struct {
|
||||
|
||||
func listDockerImages() (diis []dockerImageInfo, err error) {
|
||||
cmd := exec.Command("docker", "images")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return
|
||||
@ -648,6 +670,8 @@ func genDockerKernels(dii dockerImageInfo, newkcfg *config.KernelConfig,
|
||||
|
||||
name := dii.ContainerName
|
||||
cmd := exec.Command("docker", "run", name, "ls", "/lib/modules")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(rawOutput), err)
|
||||
|
@ -28,6 +28,8 @@ func genHostKernels(download bool) (kcfg config.KernelConfig, err error) {
|
||||
}
|
||||
|
||||
cmd := exec.Command("ls", "/lib/modules")
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
rawOutput, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Print(string(rawOutput), err)
|
||||
|
14
main.go
14
main.go
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
@ -69,6 +70,19 @@ func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
|
||||
func main() {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
|
||||
zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string {
|
||||
short := file
|
||||
for i := len(file) - 1; i > 0; i-- {
|
||||
if file[i] == '/' {
|
||||
short = file[i+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
file = short
|
||||
return file + ":" + strconv.Itoa(line)
|
||||
}
|
||||
log.Logger = log.With().Caller().Logger()
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
cli := CLI{}
|
||||
|
7
pew.go
7
pew.go
@ -174,8 +174,10 @@ func dockerRun(timeout time.Duration, container, workdir, command string) (
|
||||
}
|
||||
|
||||
func sh(workdir, cmd string) (output string, err error) {
|
||||
log.Debug().Str("workdir", workdir).Str("cmd", cmd).Msg("run command")
|
||||
command := exec.Command("sh", "-c", "cd "+workdir+" && "+cmd)
|
||||
|
||||
log.Debug().Msgf("%v", command)
|
||||
|
||||
raw, err := command.CombinedOutput()
|
||||
output = string(raw)
|
||||
if err != nil {
|
||||
@ -265,6 +267,9 @@ func build(tmp string, ka config.Artifact, ki config.KernelInfo,
|
||||
} else {
|
||||
cmd := exec.Command("bash", "-c", "cd "+outdir+" && "+
|
||||
buildCommand)
|
||||
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
timer := time.AfterFunc(dockerTimeout, func() {
|
||||
cmd.Process.Kill()
|
||||
})
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@ -257,6 +258,7 @@ func (q *System) Start() (err error) {
|
||||
qemuArgs = append(qemuArgs, "-append", q.cmdline())
|
||||
|
||||
q.cmd = exec.Command("qemu-system-"+string(q.arch), qemuArgs...)
|
||||
log.Debug().Msgf("%v", q.cmd)
|
||||
|
||||
if q.pipe.stdin, err = q.cmd.StdinPipe(); err != nil {
|
||||
return
|
||||
@ -392,6 +394,7 @@ func (q System) scp(user, localPath, remotePath string, recursive bool) (err err
|
||||
args = append(args, localPath, user+"@"+addr+":"+remotePath)
|
||||
|
||||
cmd := exec.Command("scp", args...)
|
||||
log.Debug().Msgf("%v", cmd)
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil || string(output) != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user