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