mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Inherit parent in clone(CLONE_THREAD) under TaskSet.mu.
PiperOrigin-RevId: 203849534 Change-Id: I4d81513bfd32e0b7fc40c8a4c194eba7abc35a83
This commit is contained in:
@@ -220,18 +220,15 @@ func (t *Task) Clone(opts *CloneOptions) (ThreadID, *SyscallControl, error) {
|
||||
pidns = pidns.NewChild(userns)
|
||||
}
|
||||
tg := t.tg
|
||||
parent := t.parent
|
||||
if opts.NewThreadGroup {
|
||||
sh := t.tg.signalHandlers
|
||||
if opts.NewSignalHandlers {
|
||||
sh = sh.Fork()
|
||||
}
|
||||
tg = NewThreadGroup(pidns, sh, opts.TerminationSignal, tg.limits.GetCopy(), t.k.monotonicClock)
|
||||
parent = t
|
||||
}
|
||||
cfg := &TaskConfig{
|
||||
Kernel: t.k,
|
||||
Parent: parent,
|
||||
ThreadGroup: tg,
|
||||
TaskContext: tc,
|
||||
TaskResources: t.tr.Fork(!opts.NewFiles, !opts.NewFSContext),
|
||||
@@ -242,6 +239,11 @@ func (t *Task) Clone(opts *CloneOptions) (ThreadID, *SyscallControl, error) {
|
||||
UTSNamespace: utsns,
|
||||
IPCNamespace: ipcns,
|
||||
}
|
||||
if opts.NewThreadGroup {
|
||||
cfg.Parent = t
|
||||
} else {
|
||||
cfg.InheritParent = t
|
||||
}
|
||||
if opts.NewNetworkNamespace {
|
||||
cfg.NetworkNamespaced = true
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ type TaskConfig struct {
|
||||
// Parent is the new task's parent. Parent may be nil.
|
||||
Parent *Task
|
||||
|
||||
// If InheritParent is not nil, use InheritParent's parent as the new
|
||||
// task's parent.
|
||||
InheritParent *Task
|
||||
|
||||
// ThreadGroup is the ThreadGroup the new task belongs to.
|
||||
*ThreadGroup
|
||||
|
||||
@@ -133,6 +137,9 @@ func (ts *TaskSet) newTask(cfg *TaskConfig) (*Task, error) {
|
||||
// IDs).
|
||||
t.updateLogPrefixLocked()
|
||||
|
||||
if cfg.InheritParent != nil {
|
||||
t.parent = cfg.InheritParent.parent
|
||||
}
|
||||
if t.parent != nil {
|
||||
t.parent.children[t] = struct{}{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user