@@ -43,6 +43,7 @@ type initState interface {
4343 Exec (context.Context , string , * ExecConfig ) (proc.Process , error )
4444 Kill (context.Context , uint32 , bool ) error
4545 SetExited (int )
46+ Status (context.Context ) (string , error )
4647}
4748
4849type createdState struct {
@@ -113,6 +114,10 @@ func (s *createdState) Exec(ctx context.Context, path string, r *ExecConfig) (pr
113114 return s .p .exec (ctx , path , r )
114115}
115116
117+ func (s * createdState ) Status (ctx context.Context ) (string , error ) {
118+ return "created" , nil
119+ }
120+
116121type createdCheckpointState struct {
117122 p * Init
118123 opts * runc.RestoreOpts
@@ -231,6 +236,10 @@ func (s *createdCheckpointState) Exec(ctx context.Context, path string, r *ExecC
231236 return nil , errors .Errorf ("cannot exec in a created state" )
232237}
233238
239+ func (s * createdCheckpointState ) Status (ctx context.Context ) (string , error ) {
240+ return "created" , nil
241+ }
242+
234243type runningState struct {
235244 p * Init
236245}
@@ -248,6 +257,13 @@ func (s *runningState) transition(name string) error {
248257}
249258
250259func (s * runningState ) Pause (ctx context.Context ) error {
260+ s .p .pausing .set (true )
261+ // NOTE "pausing" will be returned in the short window
262+ // after `transition("paused")`, before `pausing` is reset
263+ // to false. That doesn't break the state machine, just
264+ // delays the "paused" state a little bit.
265+ defer s .p .pausing .set (false )
266+
251267 if err := s .p .runtime .Pause (ctx , s .p .id ); err != nil {
252268 return s .p .runtimeError (err , "OCI runtime pause failed" )
253269 }
@@ -295,6 +311,10 @@ func (s *runningState) Exec(ctx context.Context, path string, r *ExecConfig) (pr
295311 return s .p .exec (ctx , path , r )
296312}
297313
314+ func (s * runningState ) Status (ctx context.Context ) (string , error ) {
315+ return "running" , nil
316+ }
317+
298318type pausedState struct {
299319 p * Init
300320}
@@ -363,6 +383,10 @@ func (s *pausedState) Exec(ctx context.Context, path string, r *ExecConfig) (pro
363383 return nil , errors .Errorf ("cannot exec in a paused state" )
364384}
365385
386+ func (s * pausedState ) Status (ctx context.Context ) (string , error ) {
387+ return "paused" , nil
388+ }
389+
366390type stoppedState struct {
367391 p * Init
368392}
@@ -419,3 +443,7 @@ func (s *stoppedState) SetExited(status int) {
419443func (s * stoppedState ) Exec (ctx context.Context , path string , r * ExecConfig ) (proc.Process , error ) {
420444 return nil , errors .Errorf ("cannot exec in a stopped state" )
421445}
446+
447+ func (s * stoppedState ) Status (ctx context.Context ) (string , error ) {
448+ return "stopped" , nil
449+ }
0 commit comments