Merge pull request #1930 from crosbymichael/proc-exists

Check that process exists before it is returned
This commit is contained in:
Kenfe-Mickaël Laventure 2017-12-27 13:05:47 -08:00 committed by GitHub
commit 3fa104f843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -235,8 +235,8 @@ func (s *Service) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*
// State returns runtime state information for a process // State returns runtime state information for a process
func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.StateResponse, error) { func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.StateResponse, error) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock()
p := s.processes[r.ID] p := s.processes[r.ID]
s.mu.Unlock()
if p == nil { if p == nil {
return nil, errdefs.ToGRPCf(errdefs.ErrNotFound, "process id %s not found", r.ID) return nil, errdefs.ToGRPCf(errdefs.ErrNotFound, "process id %s not found", r.ID)
} }

View File

@ -282,11 +282,14 @@ func (t *Task) Update(ctx context.Context, resources *types.Any) error {
// Process returns a specific process inside the task by the process id // Process returns a specific process inside the task by the process id
func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) { func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) {
// TODO: verify process exists for container p := &Process{
return &Process{
id: id, id: id,
t: t, t: t,
}, nil }
if _, err := p.State(ctx); err != nil {
return nil, err
}
return p, nil
} }
// Metrics returns runtime specific system level metric information for the task // Metrics returns runtime specific system level metric information for the task