mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add SignalContainer() to GvisorContainer for multi-containers.
SignalContainer() sends control message to signal the container in multi-container mode. PiperOrigin-RevId: 465975679
This commit is contained in:
committed by
gVisor bot
parent
208f87f387
commit
e003828a6b
@@ -290,6 +290,8 @@ func (l *Lifecycle) getInitContainerProcess(containerID string) (*kernel.ThreadG
|
||||
type ContainerArgs struct {
|
||||
// ContainerID.
|
||||
ContainerID string `json:"containerID"`
|
||||
Signo int32 `json:"signo"`
|
||||
SignalAll bool `json:"signalAll"`
|
||||
}
|
||||
|
||||
// WaitContainer waits for the container to exit and returns the exit status.
|
||||
@@ -328,3 +330,32 @@ func (l *Lifecycle) IsContainerRunning(args *ContainerArgs, isRunning *bool) err
|
||||
*isRunning = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// SignalContainer signals the container in multi-container mode. It returns error if the
|
||||
// container hasn't started or has exited.
|
||||
func (l *Lifecycle) SignalContainer(args *ContainerArgs, _ *struct{}) error {
|
||||
tg, err := l.getInitContainerProcess(args.ContainerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
l.mu.Lock()
|
||||
c, ok := l.containerMap[args.ContainerID]
|
||||
if !ok || c.state != stateRunning {
|
||||
l.mu.Unlock()
|
||||
return fmt.Errorf("%v container not running", args.ContainerID)
|
||||
}
|
||||
l.mu.Unlock()
|
||||
|
||||
// Signalling a single process is supported only for the init process.
|
||||
if !args.SignalAll {
|
||||
if tg == nil {
|
||||
return fmt.Errorf("no process exists in %v", tg)
|
||||
}
|
||||
return l.Kernel.SendExternalSignalThreadGroup(tg, &linux.SignalInfo{Signo: args.Signo})
|
||||
}
|
||||
|
||||
l.Kernel.Pause()
|
||||
defer l.Kernel.Unpause()
|
||||
return l.Kernel.SendContainerSignal(args.ContainerID, &linux.SignalInfo{Signo: args.Signo})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user