Skip to content

Instantly share code, notes, and snippets.

@gdestuynder
Created July 22, 2015 17:46
Show Gist options
  • Save gdestuynder/dbf73a1d15ecc300427e to your computer and use it in GitHub Desktop.
Save gdestuynder/dbf73a1d15ecc300427e to your computer and use it in GitHub Desktop.
package main
import "syscall"
import "os"
import "fmt"
const CLONE_NEWNS = 0x00020000
const CLONE_NEWUTS = 0x04000000
const CLONE_NEWIPC = 0x80000000
const CLONE_NEWUSER = 0x10000000
const CLONE_NEWPID = 0x20000000
const CLONE_NEWNET = 0x40000000
func main() {
var flags = CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWNET
var ws syscall.WaitStatus = 0
execSpec := &syscall.ProcAttr{
Env: os.Environ(),
Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()},
Dir: "",
}
retu := syscall.Unshare(flags)
if retu != nil {
panic(fmt.Sprintf("unshare() failed: %s", retu))
}
pid, rete := syscall.ForkExec("/bin/bash", []string{"bash"}, execSpec)
if rete != nil {
panic(rete)
} else {
syscall.Wait4(pid, &ws, 0, nil)
}
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment