X Tutup
Skip to content

Commit 9f13b41

Browse files
committed
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>
1 parent 0fa7658 commit 9f13b41

File tree

16 files changed

+283
-178
lines changed

16 files changed

+283
-178
lines changed

api/types/task/task.pb.go

Lines changed: 62 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types/task/task.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum Status {
1414
RUNNING = 2 [(gogoproto.enumvalue_customname) = "StatusRunning"];
1515
STOPPED = 3 [(gogoproto.enumvalue_customname) = "StatusStopped"];
1616
PAUSED = 4 [(gogoproto.enumvalue_customname) = "StatusPaused"];
17+
PAUSING = 5 [(gogoproto.enumvalue_customname) = "StatusPausing"];
1718
}
1819

1920
message Process {
@@ -25,4 +26,5 @@ message Process {
2526
string stdout = 6;
2627
string stderr = 7;
2728
bool terminal = 8;
29+
uint32 exit_status = 9;
2830
}

checkpoint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestCheckpointLeaveRunning(t *testing.T) {
264264
t.Error(err)
265265
return
266266
}
267-
if status != Running {
267+
if status.Status != Running {
268268
t.Errorf("expected status %q but received %q", Running, status)
269269
return
270270
}

cmd/ctr/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func deleteContainer(ctx context.Context, client *containerd.Client, id string,
5959
if err != nil {
6060
return err
6161
}
62-
if status == containerd.Stopped || status == containerd.Created {
62+
if status.Status == containerd.Stopped || status.Status == containerd.Created {
6363
if _, err := task.Delete(ctx); err != nil {
6464
return err
6565
}

container_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,13 +1028,13 @@ func TestWaitStoppedTask(t *testing.T) {
10281028
}
10291029
// wait for the task to stop then call wait again
10301030
<-statusC
1031-
_, err = task.Wait(ctx)
1032-
if err == nil {
1033-
t.Error("Wait after task exits should return an error")
1031+
status, err := task.Wait(ctx)
1032+
if err != nil {
1033+
t.Error(err)
10341034
return
10351035
}
1036-
if !errdefs.IsUnavailable(err) {
1037-
t.Errorf("Wait should return %q when task Stopped: %v", errdefs.ErrUnavailable, err)
1036+
if status != 7 {
1037+
t.Errorf("exit status from stopped task should be 7 but received %d", status)
10381038
}
10391039
}
10401040

@@ -1119,13 +1119,13 @@ func TestWaitStoppedProcess(t *testing.T) {
11191119
// wait for the exec to return
11201120
<-processStatusC
11211121
// try to wait on the process after it has stopped
1122-
_, err = process.Wait(ctx)
1123-
if err == nil {
1124-
t.Error("Wait after process exits should return an error")
1122+
status, err := process.Wait(ctx)
1123+
if err != nil {
1124+
t.Error(err)
11251125
return
11261126
}
1127-
if !errdefs.IsUnavailable(err) {
1128-
t.Errorf("Wait should return %q when process has exited: %v", errdefs.ErrUnavailable, err)
1127+
if status != 6 {
1128+
t.Errorf("exit status from stopped process should be 6 but received %d", status)
11291129
}
11301130
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
11311131
t.Error(err)

linux/process.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ func (p *Process) State(ctx context.Context) (runtime.State, error) {
4949
status = runtime.StoppedStatus
5050
case task.StatusPaused:
5151
status = runtime.PausedStatus
52-
// TODO: containerd.DeletedStatus
52+
case task.StatusPausing:
53+
status = runtime.PausingStatus
5354
}
5455
return runtime.State{
55-
Pid: response.Pid,
56-
Status: status,
57-
Stdin: response.Stdin,
58-
Stdout: response.Stdout,
59-
Stderr: response.Stderr,
60-
Terminal: response.Terminal,
56+
Pid: response.Pid,
57+
Status: status,
58+
Stdin: response.Stdin,
59+
Stdout: response.Stdout,
60+
Stderr: response.Stderr,
61+
Terminal: response.Terminal,
62+
ExitStatus: response.ExitStatus,
6163
}, nil
6264
}
6365

linux/shim/service.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,20 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
247247
status = task.StatusStopped
248248
case "paused":
249249
status = task.StatusPaused
250+
case "pausing":
251+
status = task.StatusPausing
250252
}
251253
sio := p.Stdio()
252254
return &shimapi.StateResponse{
253-
ID: p.ID(),
254-
Bundle: s.bundle,
255-
Pid: uint32(p.Pid()),
256-
Status: status,
257-
Stdin: sio.stdin,
258-
Stdout: sio.stdout,
259-
Stderr: sio.stderr,
260-
Terminal: sio.terminal,
255+
ID: p.ID(),
256+
Bundle: s.bundle,
257+
Pid: uint32(p.Pid()),
258+
Status: status,
259+
Stdin: sio.stdin,
260+
Stdout: sio.stdout,
261+
Stderr: sio.stderr,
262+
Terminal: sio.terminal,
263+
ExitStatus: uint32(p.ExitStatus()),
261264
}, nil
262265
}
263266

0 commit comments

Comments
 (0)
X Tutup