runtime: remove same function

Add EnterNetNS in virtcontainers to remove same function.

FIXes #5394

Signed-off-by: Rouzip <1226015390@qq.com>
This commit is contained in:
Rouzip
2022-10-14 23:46:05 +08:00
parent 5d17cbeef7
commit 39363ffbfb
2 changed files with 10 additions and 25 deletions

View File

@@ -1045,6 +1045,15 @@ func doNetNS(netNSPath string, cb func(ns.NetNS) error) error {
return cb(targetNS)
}
// EnterNetNS is free from any call to a go routine, and it calls
// into runtime.LockOSThread(), meaning it won't be executed in a
// different thread than the one expected by the caller.
func EnterNetNS(networkID string, cb func() error) error {
return doNetNS(networkID, func(nn ns.NetNS) error {
return cb()
})
}
func deleteNetNS(netNSPath string) error {
n, err := ns.GetNS(netNSPath)
if err != nil {