diff options
Diffstat (limited to 'workhorse/internal/helper/command/command.go')
-rw-r--r-- | workhorse/internal/helper/command/command.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/workhorse/internal/helper/command/command.go b/workhorse/internal/helper/command/command.go new file mode 100644 index 00000000000..59c8c9a3db2 --- /dev/null +++ b/workhorse/internal/helper/command/command.go @@ -0,0 +1,30 @@ +package command + +import ( + "os/exec" + "syscall" +) + +func ExitStatus(err error) (int, bool) { + if v, ok := err.(interface{ ExitCode() int }); ok { + return v.ExitCode(), true + } else if err != nil { + return -1, false + } else { + return 0, false + } +} + +func KillProcessGroup(cmd *exec.Cmd) { + if cmd == nil { + return + } + + if p := cmd.Process; p != nil && p.Pid > 0 { + // Send SIGTERM to the process group of cmd + syscall.Kill(-p.Pid, syscall.SIGTERM) + } + + // reap our child process + cmd.Wait() +} |