From 7f1bcd5ebf9221fc0260d3a2610580ceac639928 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Fri, 24 Apr 2015 18:09:56 -0400 Subject: [PATCH] Spit namespace syscall content for building on non-Linux libcontainer/configs is used by the docker user namespace proposed patchset to use IDMap for uid/gid maps across the codebase. Given the client uses some of this code, it needs to build on non-Linux. This separates out the Linux-only syscalls using build tags. Signed-off-by: Phil Estes (github: estesp) --- configs/namespaces.go | 31 +---------------------- configs/namespaces_syscall.go | 31 +++++++++++++++++++++++ configs/namespaces_syscall_unsupported.go | 15 +++++++++++ 3 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 configs/namespaces_syscall.go create mode 100644 configs/namespaces_syscall_unsupported.go diff --git a/configs/namespaces.go b/configs/namespaces.go index ac6a7fa2..2c2a9fd2 100644 --- a/configs/namespaces.go +++ b/configs/namespaces.go @@ -1,9 +1,6 @@ package configs -import ( - "fmt" - "syscall" -) +import "fmt" type NamespaceType string @@ -34,10 +31,6 @@ type Namespace struct { Path string `json:"path"` } -func (n *Namespace) Syscall() int { - return namespaceInfo[n.Type] -} - func (n *Namespace) GetPath(pid int) string { if n.Path != "" { return n.Path @@ -96,25 +89,3 @@ func (n *Namespaces) index(t NamespaceType) int { func (n *Namespaces) Contains(t NamespaceType) bool { return n.index(t) != -1 } - -var namespaceInfo = map[NamespaceType]int{ - NEWNET: syscall.CLONE_NEWNET, - NEWNS: syscall.CLONE_NEWNS, - NEWUSER: syscall.CLONE_NEWUSER, - NEWIPC: syscall.CLONE_NEWIPC, - NEWUTS: syscall.CLONE_NEWUTS, - NEWPID: syscall.CLONE_NEWPID, -} - -// CloneFlags parses the container's Namespaces options to set the correct -// flags on clone, unshare. This functions returns flags only for new namespaces. -func (n *Namespaces) CloneFlags() uintptr { - var flag int - for _, v := range *n { - if v.Path != "" { - continue - } - flag |= namespaceInfo[v.Type] - } - return uintptr(flag) -} diff --git a/configs/namespaces_syscall.go b/configs/namespaces_syscall.go new file mode 100644 index 00000000..c962999e --- /dev/null +++ b/configs/namespaces_syscall.go @@ -0,0 +1,31 @@ +// +build linux + +package configs + +import "syscall" + +func (n *Namespace) Syscall() int { + return namespaceInfo[n.Type] +} + +var namespaceInfo = map[NamespaceType]int{ + NEWNET: syscall.CLONE_NEWNET, + NEWNS: syscall.CLONE_NEWNS, + NEWUSER: syscall.CLONE_NEWUSER, + NEWIPC: syscall.CLONE_NEWIPC, + NEWUTS: syscall.CLONE_NEWUTS, + NEWPID: syscall.CLONE_NEWPID, +} + +// CloneFlags parses the container's Namespaces options to set the correct +// flags on clone, unshare. This functions returns flags only for new namespaces. +func (n *Namespaces) CloneFlags() uintptr { + var flag int + for _, v := range *n { + if v.Path != "" { + continue + } + flag |= namespaceInfo[v.Type] + } + return uintptr(flag) +} diff --git a/configs/namespaces_syscall_unsupported.go b/configs/namespaces_syscall_unsupported.go new file mode 100644 index 00000000..1bd26bd6 --- /dev/null +++ b/configs/namespaces_syscall_unsupported.go @@ -0,0 +1,15 @@ +// +build !linux + +package configs + +func (n *Namespace) Syscall() int { + panic("No namespace syscall support") + return 0 +} + +// CloneFlags parses the container's Namespaces options to set the correct +// flags on clone, unshare. This functions returns flags only for new namespaces. +func (n *Namespaces) CloneFlags() uintptr { + panic("No namespace syscall support") + return uintptr(0) +}