From 89c15bf15c0e14668bf6676be1c7cbdab02b38c0 Mon Sep 17 00:00:00 2001 From: Max Claus Nunes Date: Sun, 24 Jun 2018 20:47:46 -0300 Subject: [PATCH] Fix exit handler for successful exits --- gaper.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gaper.go b/gaper.go index e3b0a79..42451e8 100644 --- a/gaper.go +++ b/gaper.go @@ -145,18 +145,16 @@ func restart(builder Builder, runner Runner) error { } func handleProgramExit(builder Builder, runner Runner, err error, noRestartOn string) error { - exiterr, ok := err.(*exec.ExitError) - if !ok { - return fmt.Errorf("couldn't handle program crash restart: %v", err) - } + var exitStatus int + if exiterr, ok := err.(*exec.ExitError); ok { + status, oks := exiterr.Sys().(syscall.WaitStatus) + if !oks { + return fmt.Errorf("couldn't resolve exit status: %v", err) + } - status, oks := exiterr.Sys().(syscall.WaitStatus) - if !oks { - return fmt.Errorf("couldn't resolve exit status: %v", err) + exitStatus = status.ExitStatus() } - exitStatus := status.ExitStatus() - // if "error", an exit code of 0 will still restart. if noRestartOn == "error" && exitStatus == exitStatusError { return nil