Add Exec to process states
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
ba84c5fb38
commit
2a730264aa
@ -48,3 +48,7 @@ func (s *deletedState) Kill(ctx context.Context, sig uint32, all bool) error {
|
|||||||
func (s *deletedState) SetExited(status int) {
|
func (s *deletedState) SetExited(status int) {
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *deletedState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
|
return nil, errors.Errorf("cannot exec in a deleted state")
|
||||||
|
}
|
||||||
|
@ -346,8 +346,8 @@ func (p *Init) Runtime() *runc.Runc {
|
|||||||
return p.runtime
|
return p.runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec returns a new exec'd process
|
// exec returns a new exec'd process
|
||||||
func (p *Init) Exec(context context.Context, path string, r *ExecConfig) (Process, error) {
|
func (p *Init) exec(context context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
// process exec request
|
// process exec request
|
||||||
var spec specs.Process
|
var spec specs.Process
|
||||||
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
|
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
|
||||||
|
@ -22,6 +22,7 @@ type initState interface {
|
|||||||
Resume(context.Context) error
|
Resume(context.Context) error
|
||||||
Update(context.Context, *google_protobuf.Any) error
|
Update(context.Context, *google_protobuf.Any) error
|
||||||
Checkpoint(context.Context, *CheckpointConfig) error
|
Checkpoint(context.Context, *CheckpointConfig) error
|
||||||
|
Exec(context.Context, string, *ExecConfig) (Process, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type createdState struct {
|
type createdState struct {
|
||||||
@ -113,6 +114,12 @@ func (s *createdState) SetExited(status int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *createdState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
|
s.p.mu.Lock()
|
||||||
|
defer s.p.mu.Unlock()
|
||||||
|
return s.p.exec(ctx, path, r)
|
||||||
|
}
|
||||||
|
|
||||||
type createdCheckpointState struct {
|
type createdCheckpointState struct {
|
||||||
p *Init
|
p *Init
|
||||||
opts *runc.RestoreOpts
|
opts *runc.RestoreOpts
|
||||||
@ -227,6 +234,13 @@ func (s *createdCheckpointState) SetExited(status int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *createdCheckpointState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
|
s.p.mu.Lock()
|
||||||
|
defer s.p.mu.Unlock()
|
||||||
|
|
||||||
|
return nil, errors.Errorf("cannot exec in a created state")
|
||||||
|
}
|
||||||
|
|
||||||
type runningState struct {
|
type runningState struct {
|
||||||
p *Init
|
p *Init
|
||||||
}
|
}
|
||||||
@ -312,6 +326,12 @@ func (s *runningState) SetExited(status int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *runningState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
|
s.p.mu.Lock()
|
||||||
|
defer s.p.mu.Unlock()
|
||||||
|
return s.p.exec(ctx, path, r)
|
||||||
|
}
|
||||||
|
|
||||||
type pausedState struct {
|
type pausedState struct {
|
||||||
p *Init
|
p *Init
|
||||||
}
|
}
|
||||||
@ -396,7 +416,13 @@ func (s *pausedState) SetExited(status int) {
|
|||||||
if err := s.transition("stopped"); err != nil {
|
if err := s.transition("stopped"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *pausedState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
|
s.p.mu.Lock()
|
||||||
|
defer s.p.mu.Unlock()
|
||||||
|
|
||||||
|
return nil, errors.Errorf("cannot exec in a paused state")
|
||||||
}
|
}
|
||||||
|
|
||||||
type stoppedState struct {
|
type stoppedState struct {
|
||||||
@ -471,3 +497,10 @@ func (s *stoppedState) Kill(ctx context.Context, sig uint32, all bool) error {
|
|||||||
func (s *stoppedState) SetExited(status int) {
|
func (s *stoppedState) SetExited(status int) {
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *stoppedState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
|
||||||
|
s.p.mu.Lock()
|
||||||
|
defer s.p.mu.Unlock()
|
||||||
|
|
||||||
|
return nil, errors.Errorf("cannot exec in a stopped state")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user