feat: Add pidns flag

This commit is contained in:
ptrcnull 2022-01-18 14:49:41 +01:00
parent a1121f8260
commit 66aeae6166

View file

@ -12,6 +12,7 @@ import (
var rootPath = flag.String("root", "", "path to root directory") var rootPath = flag.String("root", "", "path to root directory")
var initCmd = flag.String("init", "/sbin/init", "init command") var initCmd = flag.String("init", "/sbin/init", "init command")
var workdir = flag.String("workdir", "/", "work directory") var workdir = flag.String("workdir", "/", "work directory")
var pidns = flag.Bool("pidns", false, "create pid namespace")
func main() { func main() {
flag.Parse() flag.Parse()
@ -26,7 +27,7 @@ func main() {
cmd.Dir = *workdir cmd.Dir = *workdir
cmd.SysProcAttr = &syscall.SysProcAttr{ cmd.SysProcAttr = &syscall.SysProcAttr{
Chroot: *rootPath, Chroot: *rootPath,
Cloneflags: syscall.CLONE_NEWUSER|syscall.CLONE_NEWPID, Cloneflags: syscall.CLONE_NEWUSER,
UidMappings: []syscall.SysProcIDMap{ UidMappings: []syscall.SysProcIDMap{
{ContainerID: 0, HostID: os.Getuid(), Size: 1}, {ContainerID: 0, HostID: os.Getuid(), Size: 1},
}, },
@ -34,6 +35,9 @@ func main() {
{ContainerID: 0, HostID: os.Getgid(), Size: 1}, {ContainerID: 0, HostID: os.Getgid(), Size: 1},
}, },
} }
if *pidns {
cmd.SysProcAttr.Cloneflags |= syscall.CLONE_NEWPID
}
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr