2014-02-19 02:13:36 -05:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2014-02-25 13:54:41 -05:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2014-02-19 02:13:36 -05:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2014-02-25 13:54:41 -05:00
|
|
|
// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
|
|
|
|
//
|
|
|
|
// We need different setns values for the different platforms and arch
|
|
|
|
// We are declaring the macro here because the SETNS syscall does not exist in th stdlib
|
|
|
|
var setNsMap = map[string]uintptr{
|
|
|
|
"linux/amd64": 308,
|
|
|
|
}
|
|
|
|
|
2014-02-19 02:13:36 -05:00
|
|
|
func Setns(fd uintptr, flags uintptr) error {
|
2014-02-25 13:54:41 -05:00
|
|
|
ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)]
|
|
|
|
if !exists {
|
|
|
|
return ErrNotSupportedPlatform
|
|
|
|
}
|
|
|
|
_, _, err := syscall.RawSyscall(ns, fd, flags, 0)
|
2014-02-19 02:13:36 -05:00
|
|
|
if err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|