@@ -37,6 +37,7 @@ type initState interface {
3737 Exec (context.Context , string , * ExecConfig ) (Process , error )
3838 Kill (context.Context , uint32 , bool ) error
3939 SetExited (int )
40+ Status (context.Context ) (string , error )
4041}
4142
4243type createdState struct {
@@ -103,6 +104,10 @@ func (s *createdState) Exec(ctx context.Context, path string, r *ExecConfig) (Pr
103104 return s .p .exec (ctx , path , r )
104105}
105106
107+ func (s * createdState ) Status (ctx context.Context ) (string , error ) {
108+ return "created" , nil
109+ }
110+
106111type createdCheckpointState struct {
107112 p * Init
108113 opts * runc.RestoreOpts
@@ -211,6 +216,10 @@ func (s *createdCheckpointState) Exec(ctx context.Context, path string, r *ExecC
211216 return nil , errors .Errorf ("cannot exec in a created state" )
212217}
213218
219+ func (s * createdCheckpointState ) Status (ctx context.Context ) (string , error ) {
220+ return "created" , nil
221+ }
222+
214223type runningState struct {
215224 p * Init
216225}
@@ -228,6 +237,13 @@ func (s *runningState) transition(name string) error {
228237}
229238
230239func (s * runningState ) Pause (ctx context.Context ) error {
240+ s .p .pausing .set (true )
241+ // NOTE "pausing" will be returned in the short window
242+ // after `transition("paused")`, before `pausing` is reset
243+ // to false. That doesn't break the state machine, just
244+ // delays the "paused" state a little bit.
245+ defer s .p .pausing .set (false )
246+
231247 if err := s .p .runtime .Pause (ctx , s .p .id ); err != nil {
232248 return s .p .runtimeError (err , "OCI runtime pause failed" )
233249 }
@@ -271,6 +287,10 @@ func (s *runningState) Exec(ctx context.Context, path string, r *ExecConfig) (Pr
271287 return s .p .exec (ctx , path , r )
272288}
273289
290+ func (s * runningState ) Status (ctx context.Context ) (string , error ) {
291+ return "running" , nil
292+ }
293+
274294type pausedState struct {
275295 p * Init
276296}
@@ -335,6 +355,10 @@ func (s *pausedState) Exec(ctx context.Context, path string, r *ExecConfig) (Pro
335355 return nil , errors .Errorf ("cannot exec in a paused state" )
336356}
337357
358+ func (s * pausedState ) Status (ctx context.Context ) (string , error ) {
359+ return "paused" , nil
360+ }
361+
338362type stoppedState struct {
339363 p * Init
340364}
@@ -387,3 +411,7 @@ func (s *stoppedState) SetExited(status int) {
387411func (s * stoppedState ) Exec (ctx context.Context , path string , r * ExecConfig ) (Process , error ) {
388412 return nil , errors .Errorf ("cannot exec in a stopped state" )
389413}
414+
415+ func (s * stoppedState ) Status (ctx context.Context ) (string , error ) {
416+ return "stopped" , nil
417+ }
0 commit comments