I have the following problem: I'm calling "cryptsetup" out of a go routine. Therefore, if the cryptsetup succeeds and exits with exitcode 0, everything is ok. If cryptsetup runs into an error, like a wrong password, and exits with an error code != 0, my go function only prints the error and then exits without a panic or an errorcode.
openCmd := exec.Command("cryptsetup", "luksOpen", *container, "container")
var inPipe io.WriteCloser
if inPipe, err = openCmd.StdinPipe(); err == nil {
if err = openCmd.Start(); err == nil {
log.Println("cryptsetup command started!")
inPipe.Write([]byte(pwd))
log.Println("luks password passed!")
inPipe.Close()
log.Println("stdin pipe closed!")
if err = openCmd.Wait(); err == nil {
log.Println("Container opened!")
if err = exec.Command("mount", "-t", "ext4", "/dev/mapper/container", "/mnt").Run(); err == nil {
mountStatus.isMounted = true
pwd = ""
log.Println("Container mounted!")
return true
} else {
log.Fatalf("Couldn't mount partition: %s", err)
}
} else {
log.Fatalf("cryptsetup execution failed: %s", err)
}
} else {
log.Fatalf("Couldn't start cryptsetup command: %s", err)
}
} else {
log.Fatalf("Couldn't open cryptsetup stdin: %s", err)
}
My console output looks like this:
2018/06/21 09:05:17 cryptsetup command started!
2018/06/21 09:05:17 luks password passed!
2018/06/21 09:05:17 stdin pipe closed!
2018/06/21 09:05:20 cryptsetup execution failed: exit status 2
I have no idea why my program exits. Can anyone help?