mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 02:26:37 +00:00
containerd-shim-kata-v2: add the service Kill support
Add the Kill api support to send signal to a given container process. Signed-off-by: ZeroMagic <anthonyliu@zju.edu.cn> Signed-off-by: fupan.li <lifupan@gmail.com>
This commit is contained in:
parent
9ee53be986
commit
5cc016c8a2
@ -547,7 +547,38 @@ func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*ptypes
|
||||
|
||||
// Kill a process with the provided signal
|
||||
func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (*ptypes.Empty, error) {
|
||||
return nil, errdefs.ErrNotImplemented
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
signum := syscall.Signal(r.Signal)
|
||||
|
||||
c, err := s.getContainer(r.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
processID := c.id
|
||||
if r.ExecID != "" {
|
||||
execs, err := c.getExec(r.ExecID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
processID = execs.id
|
||||
}
|
||||
|
||||
err = s.sandbox.SignalProcess(c.id, processID, signum, r.All)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Since the k8s will use the SIGTERM signal to stop a container by default, but
|
||||
// some container processes would ignore this signal such as shell, thus it's better
|
||||
// to resend another SIGKILL signal to make sure the container process terminated successfully.
|
||||
if signum == syscall.SIGTERM {
|
||||
err = s.sandbox.SignalProcess(c.id, processID, syscall.SIGKILL, r.All)
|
||||
}
|
||||
|
||||
return empty, err
|
||||
}
|
||||
|
||||
// Pids returns all pids inside the container
|
||||
|
Loading…
Reference in New Issue
Block a user