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
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
initCommand = cli.Command{
|
|
|
|
Name: "init",
|
|
|
|
Usage: "runs the init process inside the namespace",
|
|
|
|
Action: initAction,
|
2014-12-15 23:08:56 +08:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.IntFlag{"fd", 0, "internal pipe fd"},
|
|
|
|
},
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func initAction(context *cli.Context) {
|
2014-12-15 23:08:56 +08:00
|
|
|
factory, err := libcontainer.New("", []string{})
|
2014-06-06 05:28:09 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-12-15 23:08:56 +08:00
|
|
|
if context.Int("fd") == 0 {
|
|
|
|
log.Fatal("--fd must be specified for init process")
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|
|
|
|
|
2014-12-15 23:08:56 +08:00
|
|
|
fd := uintptr(context.Int("fd"))
|
|
|
|
|
|
|
|
if err := factory.StartInitialization(fd); err != nil {
|
2014-06-05 07:46:30 +08:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-12-19 17:40:03 +08:00
|
|
|
panic("This line should never been executed")
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|