1
0
mirror of https://github.com/b4tman/armhf-alpine-qemu.git synced 2024-12-05 01:26:54 +00:00

properly handle exit code of emulated process

fixes #7

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
This commit is contained in:
Petros Angelatos 2016-09-19 16:49:57 -07:00
parent 317c6a8939
commit 91d7377a71
2 changed files with 16 additions and 3 deletions

Binary file not shown.

View File

@ -4,6 +4,7 @@ import (
"log"
"os"
"os/exec"
"syscall"
)
func crossBuildStart() {
@ -28,12 +29,12 @@ func crossBuildEnd() {
}
}
func runShell() {
func runShell() error {
cmd := exec.Command("/usr/bin/qemu-arm-static", append([]string{"-0", "/bin/sh", "/bin/sh"}, os.Args[1:]...)...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
return cmd.Run()
}
func main() {
@ -43,8 +44,20 @@ func main() {
case "cross-build-end":
crossBuildEnd()
case "/bin/sh":
code := 0
crossBuildEnd()
runShell()
if err := runShell(); err != nil {
code = 1
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
code = status.ExitStatus()
}
}
}
crossBuildStart()
os.Exit(code)
}
}