Return exit status from Wait of stopped process
This changes Wait() from returning an error whenever you call wait on a stopped process/task to returning the exit status from the process. This also adds the exit status to the Status() call on a process/task so that a user can Wait(), check status, then cancel the wait to avoid races in event handling. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -44,21 +44,26 @@ func (t *task) ID() string {
|
||||
}
|
||||
|
||||
func (t *task) State(ctx context.Context) (runtime.State, error) {
|
||||
var status runtime.Status
|
||||
var (
|
||||
status runtime.Status
|
||||
exitStatus uint32
|
||||
)
|
||||
|
||||
if p := t.getProcess(t.id); p != nil {
|
||||
status = p.Status()
|
||||
exitStatus = p.exitCode
|
||||
} else {
|
||||
status = t.getStatus()
|
||||
}
|
||||
|
||||
return runtime.State{
|
||||
Status: status,
|
||||
Pid: t.pid,
|
||||
Stdin: t.io.src.Stdin,
|
||||
Stdout: t.io.src.Stdout,
|
||||
Stderr: t.io.src.Stderr,
|
||||
Terminal: t.io.src.Terminal,
|
||||
Status: status,
|
||||
Pid: t.pid,
|
||||
Stdin: t.io.src.Stdin,
|
||||
Stdout: t.io.src.Stdout,
|
||||
Stderr: t.io.src.Stderr,
|
||||
Terminal: t.io.src.Terminal,
|
||||
ExitStatus: exitStatus,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user