Clean up return values from RunProcessOne

This commit is contained in:
Brian Picciano 2022-06-30 13:42:57 -06:00
parent 881bd83086
commit a451ee620c

View File

@ -86,12 +86,11 @@ func sigProcessGroup(sysLogger Logger, proc *os.Process, sig syscall.Signal) {
} }
// RunProcessOnce runs the process described by the ProcessConfig (though it // RunProcessOnce runs the process described by the ProcessConfig (though it
// doesn't use all fields from the ProcessConfig). The process is killed iff the // doesn't use all fields from the ProcessConfig).
// context is canceled. The exit status of the process is returned, or -1 if the
// process was never started.
// //
// It returns nil if the process exits normally with a zero status. It returns // The process is killed if-and-only-if the context is canceled, returning -1
// an error otherwise. // and context.Canceled. Otherwise the exit status of the process is returned,
// or -1 and an error.
// //
// The stdout and stderr of the process will be written to the corresponding // The stdout and stderr of the process will be written to the corresponding
// Loggers. Various runtime events will be written to the sysLogger. // Loggers. Various runtime events will be written to the sysLogger.
@ -186,13 +185,15 @@ func RunProcessOnce(
err = cmd.Wait() err = cmd.Wait()
close(stopCh) close(stopCh)
exitCode := cmd.ProcessState.ExitCode() if err := ctx.Err(); err != nil {
return -1, err
if err != nil {
return exitCode, fmt.Errorf("process exited: %w", err)
} }
return exitCode, nil if err != nil {
return -1, fmt.Errorf("process exited: %w", err)
}
return cmd.ProcessState.ExitCode(), nil
} }
// RunProcess runs a process (configured by ProcessConfig) until the context is // RunProcess runs a process (configured by ProcessConfig) until the context is
@ -224,9 +225,9 @@ func RunProcess(
took := time.Since(start) took := time.Since(start)
if err != nil { if err != nil {
sysLogger.Printf("exit code %d, %v", exitCode, err) sysLogger.Printf("exited: %v", err)
} else { } else {
sysLogger.Println("exit code 0") sysLogger.Printf("exit code: %d", exitCode)
} }
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {