Add SignalProcess control method.

PiperOrigin-RevId: 662259919
This commit is contained in:
Nicolas Lacasse
2024-08-12 16:07:19 -07:00
committed by gVisor bot
parent 4f594794b8
commit 63e04396fa
+18 -2
View File
@@ -40,8 +40,6 @@ import (
)
// Proc includes task-related functions.
//
// At the moment, this is limited to exec support.
type Proc struct {
Kernel *kernel.Kernel
}
@@ -519,3 +517,21 @@ func (args *ExecArgs) unpackFiles() (map[int]*fd.FD, *fd.FD, error) {
}
return fdMap, execFD, nil
}
// SignalProcessArgs is the arguments to SignalProcess.
type SignalProcessArgs struct {
// Signal number to send.
Signo int `json:"signo"`
// Process ID (in the root PID namespace) to signal.
PID int `json:"pid"`
}
// SignalProcess sends a signal to the process with the given PID.
func (proc *Proc) SignalProcess(args *SignalProcessArgs, _ *struct{}) error {
tg := proc.Kernel.RootPIDNamespace().ThreadGroupWithID(kernel.ThreadID(args.PID))
if tg == nil {
return fmt.Errorf("no such process with PID %d", args.PID)
}
return proc.Kernel.SendExternalSignalThreadGroup(tg, &linux.SignalInfo{Signo: int32(args.Signo)})
}