fix: persist netns before restoring origin network namespace
This commit is contained in:
parent
500d6ad57c
commit
3422b93159
@ -27,17 +27,17 @@ func New() (handle NsHandle, error error) {
|
||||
return None(), err
|
||||
}
|
||||
|
||||
err = Set(origins)
|
||||
if err != nil {
|
||||
return NsHandle{Fd: 0}, err
|
||||
}
|
||||
|
||||
err = newNs.persist()
|
||||
if err != nil {
|
||||
defer deferClose(&newNs, &error)
|
||||
return newNs, err
|
||||
}
|
||||
|
||||
err = Set(origins)
|
||||
if err != nil {
|
||||
return NsHandle{Fd: 0}, err
|
||||
}
|
||||
|
||||
return newNs, nil
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,7 @@ func (ns *NsHandle) persist() error {
|
||||
return err
|
||||
}
|
||||
|
||||
nsPath := GetPath()
|
||||
err = unix.Mount(nsPath, namedPath, "bind", unix.MS_BIND, "")
|
||||
err = unix.Mount(GetPath(), namedPath, "bind", unix.MS_BIND, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -71,9 +70,9 @@ func (ns *NsHandle) String() string {
|
||||
}
|
||||
var s unix.Stat_t
|
||||
if err := unix.Fstat(ns.Fd, &s); err != nil {
|
||||
return fmt.Sprintf("NS(%d: unknown)", ns)
|
||||
return fmt.Sprintf("NS(%d: unknown)", ns.Fd)
|
||||
}
|
||||
return fmt.Sprintf("NS(%d: %d, %d)", ns, s.Dev, s.Ino)
|
||||
return fmt.Sprintf("NS(%d: %d, %d)", ns.Fd, s.Dev, s.Ino)
|
||||
}
|
||||
|
||||
// IsOpen returns true if Close() has not been called.
|
||||
|
Loading…
Reference in New Issue
Block a user