Use flag for init
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
This commit is contained in:
parent
ccc915b7b9
commit
3677967f4e
2 changed files with 12 additions and 9 deletions
|
@ -164,7 +164,7 @@ func deletePidFile() error {
|
|||
// defined on the container's configuration and use the current binary as the init with the
|
||||
// args provided
|
||||
func createCommand(container *libcontainer.Container, console string, args []string) *exec.Cmd {
|
||||
command := exec.Command("nsinit", append([]string{"init", console}, args...)...)
|
||||
command := exec.Command("nsinit", append([]string{"-console", console, "init"}, args...)...)
|
||||
command.SysProcAttr = &syscall.SysProcAttr{
|
||||
Cloneflags: uintptr(getNamespaceFlags(container.Namespaces)),
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -16,16 +17,18 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
console := flag.String("console", "", "Console (pty slave) name")
|
||||
flag.Parse()
|
||||
|
||||
container, err := loadContainer()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
argc := len(os.Args)
|
||||
if argc < 2 {
|
||||
if flag.NArg() < 1 {
|
||||
log.Fatal(ErrWrongArguments)
|
||||
}
|
||||
switch os.Args[1] {
|
||||
switch flag.Arg(0) {
|
||||
case "exec": // this is executed outside of the namespace in the cwd
|
||||
var exitCode int
|
||||
nspid, err := readPid()
|
||||
|
@ -35,23 +38,23 @@ func main() {
|
|||
}
|
||||
}
|
||||
if nspid > 0 {
|
||||
exitCode, err = execinCommand(container, nspid, os.Args[2:])
|
||||
exitCode, err = execinCommand(container, nspid, flag.Args()[1:])
|
||||
} else {
|
||||
exitCode, err = execCommand(container, os.Args[2:])
|
||||
exitCode, err = execCommand(container, flag.Args()[1:])
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
case "init": // this is executed inside of the namespace to setup the container
|
||||
if argc < 3 {
|
||||
if flag.NArg() < 2 {
|
||||
log.Fatal(ErrWrongArguments)
|
||||
}
|
||||
if err := initCommand(container, os.Args[2], os.Args[3:]); err != nil {
|
||||
if err := initCommand(container, *console, flag.Args()[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
default:
|
||||
log.Fatalf("command not supported for nsinit %s", os.Args[1])
|
||||
log.Fatalf("command not supported for nsinit %s", flag.Arg(0))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue