2014-08-13 01:46:43 +08:00
|
|
|
package main
|
2014-06-05 07:46:30 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2014-12-15 23:08:56 +08:00
|
|
|
"github.com/docker/libcontainer"
|
2014-12-23 06:06:22 +08:00
|
|
|
_ "github.com/docker/libcontainer/namespaces/nsenter"
|
2014-06-05 07:46:30 +08:00
|
|
|
)
|
|
|
|
|
2015-02-01 12:51:12 +08:00
|
|
|
var initCommand = cli.Command{
|
|
|
|
Name: "init",
|
|
|
|
Usage: "runs the init process inside the namespace",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.IntFlag{Name: "fd", Value: 0, Usage: "internal pipe fd"},
|
|
|
|
},
|
|
|
|
Action: func(context *cli.Context) {
|
|
|
|
factory, err := libcontainer.New("", nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if context.Int("fd") == 0 {
|
|
|
|
log.Fatal("--fd must be specified for init process")
|
|
|
|
}
|
|
|
|
fd := uintptr(context.Int("fd"))
|
|
|
|
if err := factory.StartInitialization(fd); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
panic("This line should never been executed")
|
|
|
|
},
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|