@@ -14,6 +14,7 @@ import (
1414 "syscall"
1515 "time"
1616
17+ "github.com/docker/docker/internal/unshare"
1718 "github.com/docker/docker/libnetwork/ns"
1819 "github.com/docker/docker/libnetwork/osl/kernel"
1920 "github.com/docker/docker/libnetwork/types"
@@ -70,10 +71,6 @@ func SetBasePath(path string) {
7071 prefix = path
7172}
7273
73- func init () {
74- reexec .Register ("netns-create" , reexecCreateNamespace )
75- }
76-
7774func basePath () string {
7875 return filepath .Join (prefix , "netns" )
7976}
@@ -301,35 +298,18 @@ func GetSandboxForExternalKey(basePath string, key string) (Sandbox, error) {
301298 return n , nil
302299}
303300
304- func reexecCreateNamespace () {
305- if len (os .Args ) < 2 {
306- logrus .Fatal ("no namespace path provided" )
307- }
308- if err := mountNetworkNamespace ("/proc/self/ns/net" , os .Args [1 ]); err != nil {
309- logrus .Fatal (err )
310- }
311- }
312-
313301func createNetworkNamespace (path string , osCreate bool ) error {
314302 if err := createNamespaceFile (path ); err != nil {
315303 return err
316304 }
317305
318- cmd := & exec.Cmd {
319- Path : reexec .Self (),
320- Args : append ([]string {"netns-create" }, path ),
321- Stdout : os .Stdout ,
322- Stderr : os .Stderr ,
306+ do := func () error {
307+ return mountNetworkNamespace (fmt .Sprintf ("/proc/self/task/%d/ns/net" , unix .Gettid ()), path )
323308 }
324309 if osCreate {
325- cmd .SysProcAttr = & syscall.SysProcAttr {}
326- cmd .SysProcAttr .Cloneflags = syscall .CLONE_NEWNET
310+ return unshare .Go (unix .CLONE_NEWNET , do , nil )
327311 }
328- if err := cmd .Run (); err != nil {
329- return fmt .Errorf ("namespace creation reexec command failed: %v" , err )
330- }
331-
332- return nil
312+ return do ()
333313}
334314
335315func unmountNamespaceFile (path string ) {
0 commit comments