mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Synchronize signalling with S/R
This is to fix a data race between sending an external signal to a ThreadGroup and kernel saving state for S/R. PiperOrigin-RevId: 295244281
This commit is contained in:
@@ -1169,6 +1169,14 @@ func (k *Kernel) SendExternalSignal(info *arch.SignalInfo, context string) {
|
||||
k.sendExternalSignal(info, context)
|
||||
}
|
||||
|
||||
// SendExternalSignalThreadGroup injects a signal into an specific ThreadGroup.
|
||||
// This function doesn't skip signals like SendExternalSignal does.
|
||||
func (k *Kernel) SendExternalSignalThreadGroup(tg *ThreadGroup, info *arch.SignalInfo) error {
|
||||
k.extMu.Lock()
|
||||
defer k.extMu.Unlock()
|
||||
return tg.SendSignal(info)
|
||||
}
|
||||
|
||||
// SendContainerSignal sends the given signal to all processes inside the
|
||||
// namespace that match the given container ID.
|
||||
func (k *Kernel) SendContainerSignal(cid string, info *arch.SignalInfo) error {
|
||||
|
||||
@@ -997,7 +997,7 @@ func (l *Loader) signalProcess(cid string, tgid kernel.ThreadID, signo int32) er
|
||||
execTG, _, err := l.threadGroupFromID(execID{cid: cid, pid: tgid})
|
||||
if err == nil {
|
||||
// Send signal directly to the identified process.
|
||||
return execTG.SendSignal(&arch.SignalInfo{Signo: signo})
|
||||
return l.k.SendExternalSignalThreadGroup(execTG, &arch.SignalInfo{Signo: signo})
|
||||
}
|
||||
|
||||
// The caller may be signaling a process not started directly via exec.
|
||||
@@ -1014,7 +1014,7 @@ func (l *Loader) signalProcess(cid string, tgid kernel.ThreadID, signo int32) er
|
||||
if tg.Leader().ContainerID() != cid {
|
||||
return fmt.Errorf("process %d is part of a different container: %q", tgid, tg.Leader().ContainerID())
|
||||
}
|
||||
return tg.SendSignal(&arch.SignalInfo{Signo: signo})
|
||||
return l.k.SendExternalSignalThreadGroup(tg, &arch.SignalInfo{Signo: signo})
|
||||
}
|
||||
|
||||
func (l *Loader) signalForegrondProcessGroup(cid string, tgid kernel.ThreadID, signo int32) error {
|
||||
@@ -1032,7 +1032,7 @@ func (l *Loader) signalForegrondProcessGroup(cid string, tgid kernel.ThreadID, s
|
||||
// No foreground process group has been set. Signal the
|
||||
// original thread group.
|
||||
log.Warningf("No foreground process group for container %q and PID %d. Sending signal directly to PID %d.", cid, tgid, tgid)
|
||||
return tg.SendSignal(&arch.SignalInfo{Signo: signo})
|
||||
return l.k.SendExternalSignalThreadGroup(tg, &arch.SignalInfo{Signo: signo})
|
||||
}
|
||||
// Send the signal to all processes in the process group.
|
||||
var lastErr error
|
||||
@@ -1040,7 +1040,7 @@ func (l *Loader) signalForegrondProcessGroup(cid string, tgid kernel.ThreadID, s
|
||||
if tg.ProcessGroup() != pg {
|
||||
continue
|
||||
}
|
||||
if err := tg.SendSignal(&arch.SignalInfo{Signo: signo}); err != nil {
|
||||
if err := l.k.SendExternalSignalThreadGroup(tg, &arch.SignalInfo{Signo: signo}); err != nil {
|
||||
lastErr = err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user