mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 22:37:14 +08:00
d572094b75
A new constructor function (like nsenter) is added in this patch. This function gets arguments from environment variables and its behaviour doesn't depend on a command line arguments. A program which calls factory.StartInitialization() must import the nsenter package. It looks ugly, but I don't know another way how to enter into CT from a go code. Signed-off-by: Andrey Vagin <avagin@openvz.org>
40 lines
738 B
Go
40 lines
738 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/codegangsta/cli"
|
|
"github.com/docker/libcontainer"
|
|
_ "github.com/docker/libcontainer/namespaces/nsenter"
|
|
)
|
|
|
|
var (
|
|
initCommand = cli.Command{
|
|
Name: "init",
|
|
Usage: "runs the init process inside the namespace",
|
|
Action: initAction,
|
|
Flags: []cli.Flag{
|
|
cli.IntFlag{"fd", 0, "internal pipe fd"},
|
|
},
|
|
}
|
|
)
|
|
|
|
func initAction(context *cli.Context) {
|
|
factory, err := libcontainer.New("", []string{})
|
|
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")
|
|
}
|