diff --git a/util/iocommand.go b/util/iocommand.go index 406e98f..0433446 100644 --- a/util/iocommand.go +++ b/util/iocommand.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "os" "os/exec" "syscall" ) @@ -88,9 +89,23 @@ func (c *IOCommand) Read(buf []byte) (n int, err error) { func (c *IOCommand) doWait() (err error) { waitErr := c.Cmd.Wait() - waitStatus := c.Cmd.ProcessState.Sys().(syscall.WaitStatus) // Fail hard if we're not on UNIX + var wasUs bool = false + var waitStatus syscall.WaitStatus + if c.Cmd.ProcessState == nil { + fmt.Fprintf(os.Stderr, "util.IOCommand: c.Cmd.ProcessState is nil after c.Cmd.Wait()\n") + } + if c.Cmd.ProcessState != nil { + sysSpecific := c.Cmd.ProcessState.Sys() + var ok bool + waitStatus, ok = sysSpecific.(syscall.WaitStatus) + if !ok { + fmt.Fprintf(os.Stderr, "util.IOCommand: c.Cmd.ProcessState.Sys() could not be converted to syscall.WaitStatus: %T\n", sysSpecific) + os.Stderr.Sync() + panic(sysSpecific) // this can only be true if we are not on UNIX, and we don't support that + } + wasUs = waitStatus.Signaled() && waitStatus.Signal() == syscall.SIGTERM // in Close() + } - wasUs := waitStatus.Signaled() && waitStatus.Signal() == syscall.SIGTERM // in Close() if waitErr != nil && !wasUs { err = IOCommandError{ WaitErr: waitErr,