github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/shim/proc/deleted_state.go (about)

     1  // Copyright 2018 The containerd Authors.
     2  // Copyright 2018 The gVisor Authors.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     https://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package proc
    17  
    18  import (
    19  	"context"
    20  	"fmt"
    21  
    22  	"github.com/containerd/console"
    23  	"github.com/containerd/containerd/errdefs"
    24  	"github.com/containerd/containerd/pkg/process"
    25  	runc "github.com/containerd/go-runc"
    26  )
    27  
    28  type deletedState struct{}
    29  
    30  func (*deletedState) Resize(console.WinSize) error {
    31  	return fmt.Errorf("cannot resize a deleted container/process")
    32  }
    33  
    34  func (*deletedState) Start(context.Context) error {
    35  	return fmt.Errorf("cannot start a deleted container/process")
    36  }
    37  
    38  func (*deletedState) Delete(context.Context) error {
    39  	return fmt.Errorf("cannot delete a deleted container/process: %w", errdefs.ErrNotFound)
    40  }
    41  
    42  func (*deletedState) Kill(_ context.Context, signal uint32, _ bool) error {
    43  	return handleStoppedKill(signal)
    44  }
    45  
    46  func (*deletedState) SetExited(int) {}
    47  
    48  func (*deletedState) Exec(context.Context, string, *ExecConfig) (process.Process, error) {
    49  	return nil, fmt.Errorf("cannot exec in a deleted state")
    50  }
    51  
    52  func (s *deletedState) State(context.Context) (string, error) {
    53  	// There is no "deleted" state, closest one is stopped.
    54  	return "stopped", nil
    55  }
    56  
    57  func (s *deletedState) Stats(context.Context, string) (*runc.Stats, error) {
    58  	return nil, fmt.Errorf("cannot stat a stopped container/process")
    59  }