From 3195ea9cc631b09f051dd33881ddabf9e2fc49e1 Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 16 Sep 2015 16:44:12 +0200 Subject: [PATCH 1/4] dosc: mark CLONE_ flags as deprecated --- netns_linux.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netns_linux.go b/netns_linux.go index abdc308..1003607 100644 --- a/netns_linux.go +++ b/netns_linux.go @@ -13,8 +13,7 @@ import ( ) const ( - // These constants belong in the syscall library but have not been - // added yet. + // Deprecated: use syscall pkg instead (go >= 1.5 needed). CLONE_NEWUTS = 0x04000000 /* New utsname group? */ CLONE_NEWIPC = 0x08000000 /* New ipcs */ CLONE_NEWUSER = 0x10000000 /* New user namespace */ From 3e1d42c9bcf094d5f9f424e3d862535818959362 Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 16 Sep 2015 16:47:11 +0200 Subject: [PATCH 2/4] refactor: remove netns_linux_*.go files and use map instead --- netns_linux.go | 10 ++++++++++ netns_linux_386.go | 7 ------- netns_linux_amd64.go | 7 ------- netns_linux_arm.go | 7 ------- netns_linux_arm64.go | 7 ------- netns_linux_ppc64le.go | 7 ------- netns_linux_s390x.go | 7 ------- 7 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 netns_linux_386.go delete mode 100644 netns_linux_amd64.go delete mode 100644 netns_linux_arm.go delete mode 100644 netns_linux_arm64.go delete mode 100644 netns_linux_ppc64le.go delete mode 100644 netns_linux_s390x.go diff --git a/netns_linux.go b/netns_linux.go index 1003607..935dfab 100644 --- a/netns_linux.go +++ b/netns_linux.go @@ -7,11 +7,21 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strconv" "strings" "syscall" ) +var SYS_SETNS = map[string]uintptr{ + "386": 346, + "amd64": 308, + "arm64": 268, + "arm": 375, + "ppc64le": 350, + "s390x": 339, +}[runtime.GOARCH] + const ( // Deprecated: use syscall pkg instead (go >= 1.5 needed). CLONE_NEWUTS = 0x04000000 /* New utsname group? */ diff --git a/netns_linux_386.go b/netns_linux_386.go deleted file mode 100644 index 1d769bb..0000000 --- a/netns_linux_386.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux,386 - -package netns - -const ( - SYS_SETNS = 346 -) diff --git a/netns_linux_amd64.go b/netns_linux_amd64.go deleted file mode 100644 index b124666..0000000 --- a/netns_linux_amd64.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux,amd64 - -package netns - -const ( - SYS_SETNS = 308 -) diff --git a/netns_linux_arm.go b/netns_linux_arm.go deleted file mode 100644 index 9c74eb5..0000000 --- a/netns_linux_arm.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux,arm - -package netns - -const ( - SYS_SETNS = 375 -) diff --git a/netns_linux_arm64.go b/netns_linux_arm64.go deleted file mode 100644 index 741a302..0000000 --- a/netns_linux_arm64.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux,arm64 - -package netns - -const ( - SYS_SETNS = 268 -) diff --git a/netns_linux_ppc64le.go b/netns_linux_ppc64le.go deleted file mode 100644 index c49eba5..0000000 --- a/netns_linux_ppc64le.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux,ppc64le - -package netns - -const ( - SYS_SETNS = 350 -) diff --git a/netns_linux_s390x.go b/netns_linux_s390x.go deleted file mode 100644 index cc13e62..0000000 --- a/netns_linux_s390x.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux,s390x - -package netns - -const ( - SYS_SETNS = 339 -) From f19e34ff16fb152a4ee87ee57f5d4ec50e2c810e Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 16 Sep 2015 16:52:32 +0200 Subject: [PATCH 3/4] dosc: fix golint errors --- netns.go | 2 +- netns_linux.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/netns.go b/netns.go index 2ca0fee..df04d2a 100644 --- a/netns.go +++ b/netns.go @@ -61,7 +61,7 @@ func (ns *NsHandle) Close() error { return nil } -// Get an empty (closed) NsHandle +// None gets an empty (closed) NsHandle. func None() NsHandle { return NsHandle(-1) } diff --git a/netns_linux.go b/netns_linux.go index 935dfab..346dddc 100644 --- a/netns_linux.go +++ b/netns_linux.go @@ -13,6 +13,7 @@ import ( "syscall" ) +// SYS_SETNS syscall allows changing the namespace of the current process. var SYS_SETNS = map[string]uintptr{ "386": 346, "amd64": 308, @@ -22,8 +23,8 @@ var SYS_SETNS = map[string]uintptr{ "s390x": 339, }[runtime.GOARCH] +// Deprecated: use syscall pkg instead (go >= 1.5 needed). const ( - // Deprecated: use syscall pkg instead (go >= 1.5 needed). CLONE_NEWUTS = 0x04000000 /* New utsname group? */ CLONE_NEWIPC = 0x08000000 /* New ipcs */ CLONE_NEWUSER = 0x10000000 /* New user namespace */ From dff3fd240d505e3a1c1a51cd25399f6bef2d7de4 Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 16 Sep 2015 17:01:26 +0200 Subject: [PATCH 4/4] docs: fix typo --- netns_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netns_linux.go b/netns_linux.go index 346dddc..c160c06 100644 --- a/netns_linux.go +++ b/netns_linux.go @@ -177,7 +177,7 @@ func getPidForContainer(id string) (int, error) { filepath.Join(cgroupRoot, cgroupThis, id, "tasks"), // With more recent lxc versions use, cgroup will be in lxc/ filepath.Join(cgroupRoot, cgroupThis, "lxc", id, "tasks"), - // With more recent dockee, cgroup will be in docker/ + // With more recent docker, cgroup will be in docker/ filepath.Join(cgroupRoot, cgroupThis, "docker", id, "tasks"), }