diff --git a/internal/netns/netns.go b/internal/netns/netns.go index 0666b53..8a7d958 100644 --- a/internal/netns/netns.go +++ b/internal/netns/netns.go @@ -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 } diff --git a/internal/netns/nshandle.go b/internal/netns/nshandle.go index 8aafabe..c955264 100644 --- a/internal/netns/nshandle.go +++ b/internal/netns/nshandle.go @@ -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.