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:
Michael Crosby
2017-08-03 17:09:16 -04:00
parent 0fa76584f8
commit 9f13b414b9
16 changed files with 283 additions and 178 deletions

View File

@@ -43,6 +43,7 @@ const (
StatusRunning Status = 2
StatusStopped Status = 3
StatusPaused Status = 4
StatusPausing Status = 5
)
var Status_name = map[int32]string{
@@ -51,6 +52,7 @@ var Status_name = map[int32]string{
2: "RUNNING",
3: "STOPPED",
4: "PAUSED",
5: "PAUSING",
}
var Status_value = map[string]int32{
"UNKNOWN": 0,
@@ -58,6 +60,7 @@ var Status_value = map[string]int32{
"RUNNING": 2,
"STOPPED": 3,
"PAUSED": 4,
"PAUSING": 5,
}
func (x Status) String() string {
@@ -74,6 +77,7 @@ type Process struct {
Stdout string `protobuf:"bytes,6,opt,name=stdout,proto3" json:"stdout,omitempty"`
Stderr string `protobuf:"bytes,7,opt,name=stderr,proto3" json:"stderr,omitempty"`
Terminal bool `protobuf:"varint,8,opt,name=terminal,proto3" json:"terminal,omitempty"`
ExitStatus uint32 `protobuf:"varint,9,opt,name=exit_status,json=exitStatus,proto3" json:"exit_status,omitempty"`
}
func (m *Process) Reset() { *m = Process{} }
@@ -149,6 +153,11 @@ func (m *Process) MarshalTo(dAtA []byte) (int, error) {
}
i++
}
if m.ExitStatus != 0 {
dAtA[i] = 0x48
i++
i = encodeVarintTask(dAtA, i, uint64(m.ExitStatus))
}
return i, nil
}
@@ -211,6 +220,9 @@ func (m *Process) Size() (n int) {
if m.Terminal {
n += 2
}
if m.ExitStatus != 0 {
n += 1 + sovTask(uint64(m.ExitStatus))
}
return n
}
@@ -240,6 +252,7 @@ func (this *Process) String() string {
`Stdout:` + fmt.Sprintf("%v", this.Stdout) + `,`,
`Stderr:` + fmt.Sprintf("%v", this.Stderr) + `,`,
`Terminal:` + fmt.Sprintf("%v", this.Terminal) + `,`,
`ExitStatus:` + fmt.Sprintf("%v", this.ExitStatus) + `,`,
`}`,
}, "")
return s
@@ -484,6 +497,25 @@ func (m *Process) Unmarshal(dAtA []byte) error {
}
}
m.Terminal = bool(v != 0)
case 9:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field ExitStatus", wireType)
}
m.ExitStatus = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTask
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.ExitStatus |= (uint32(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipTask(dAtA[iNdEx:])
@@ -615,33 +647,34 @@ func init() {
}
var fileDescriptorTask = []byte{
// 436 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x3f, 0x6f, 0xd3, 0x40,
0x18, 0xc6, 0x73, 0x4e, 0xeb, 0x84, 0xeb, 0x1f, 0xcc, 0x51, 0x55, 0x87, 0x41, 0x57, 0x8b, 0x29,
0x62, 0xb0, 0x45, 0xbb, 0xb1, 0xb5, 0x71, 0x84, 0x22, 0x24, 0xd7, 0xba, 0x34, 0x62, 0x44, 0x4e,
0xee, 0x30, 0xa7, 0xb6, 0x77, 0xd6, 0xf9, 0x0c, 0xea, 0xc6, 0x88, 0xfa, 0x1d, 0x3a, 0xc1, 0x67,
0x60, 0xe0, 0x13, 0x74, 0x64, 0x64, 0xaa, 0x88, 0x3f, 0x08, 0x42, 0x3e, 0x87, 0x90, 0xa1, 0x8b,
0xf5, 0x3e, 0xcf, 0xef, 0xa7, 0xf7, 0xb5, 0x65, 0xf8, 0x2a, 0x17, 0xe6, 0x43, 0x35, 0x0b, 0xe7,
0xea, 0x32, 0x9a, 0x2b, 0x69, 0x32, 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x71, 0x5a, 0x16,
0x75, 0xbb, 0xa2, 0xaa, 0xbd, 0xd7, 0x7e, 0x5b, 0x61, 0xca, 0x32, 0x67, 0xef, 0xf3, 0x57, 0xb7,
0xf3, 0xfd, 0x9b, 0xdb, 0x5c, 0x73, 0x62, 0xdf, 0xad, 0xdd, 0xce, 0xaf, 0xb5, 0xdb, 0xf9, 0x54,
0xb9, 0xe0, 0xae, 0x72, 0xc1, 0x8f, 0xca, 0x05, 0xbf, 0x2b, 0x17, 0x2c, 0x4d, 0xfd, 0x6f, 0x1c,
0xfd, 0x09, 0x00, 0x00, 0xff, 0xff, 0x22, 0xfa, 0xb5, 0x46, 0x9f, 0x02, 0x00, 0x00,
}

View File

@@ -14,6 +14,7 @@ enum Status {
RUNNING = 2 [(gogoproto.enumvalue_customname) = "StatusRunning"];
STOPPED = 3 [(gogoproto.enumvalue_customname) = "StatusStopped"];
PAUSED = 4 [(gogoproto.enumvalue_customname) = "StatusPaused"];
PAUSING = 5 [(gogoproto.enumvalue_customname) = "StatusPausing"];
}
message Process {
@@ -25,4 +26,5 @@ message Process {
string stdout = 6;
string stderr = 7;
bool terminal = 8;
uint32 exit_status = 9;
}