Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
| ... | ... |
@@ -164,7 +164,7 @@ func deletePidFile() error {
|
| 164 | 164 |
// defined on the container's configuration and use the current binary as the init with the |
| 165 | 165 |
// args provided |
| 166 | 166 |
func createCommand(container *libcontainer.Container, console string, args []string) *exec.Cmd {
|
| 167 |
- command := exec.Command("nsinit", append([]string{"init", console}, args...)...)
|
|
| 167 |
+ command := exec.Command("nsinit", append([]string{"-console", console, "init"}, args...)...)
|
|
| 168 | 168 |
command.SysProcAttr = &syscall.SysProcAttr{
|
| 169 | 169 |
Cloneflags: uintptr(getNamespaceFlags(container.Namespaces)), |
| 170 | 170 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 | 5 |
"errors" |
| 6 |
+ "flag" |
|
| 6 | 7 |
"github.com/dotcloud/docker/pkg/libcontainer" |
| 7 | 8 |
"io/ioutil" |
| 8 | 9 |
"log" |
| ... | ... |
@@ -16,16 +17,18 @@ var ( |
| 16 | 16 |
) |
| 17 | 17 |
|
| 18 | 18 |
func main() {
|
| 19 |
+ console := flag.String("console", "", "Console (pty slave) name")
|
|
| 20 |
+ flag.Parse() |
|
| 21 |
+ |
|
| 19 | 22 |
container, err := loadContainer() |
| 20 | 23 |
if err != nil {
|
| 21 | 24 |
log.Fatal(err) |
| 22 | 25 |
} |
| 23 | 26 |
|
| 24 |
- argc := len(os.Args) |
|
| 25 |
- if argc < 2 {
|
|
| 27 |
+ if flag.NArg() < 1 {
|
|
| 26 | 28 |
log.Fatal(ErrWrongArguments) |
| 27 | 29 |
} |
| 28 |
- switch os.Args[1] {
|
|
| 30 |
+ switch flag.Arg(0) {
|
|
| 29 | 31 |
case "exec": // this is executed outside of the namespace in the cwd |
| 30 | 32 |
var exitCode int |
| 31 | 33 |
nspid, err := readPid() |
| ... | ... |
@@ -35,23 +38,23 @@ func main() {
|
| 35 | 35 |
} |
| 36 | 36 |
} |
| 37 | 37 |
if nspid > 0 {
|
| 38 |
- exitCode, err = execinCommand(container, nspid, os.Args[2:]) |
|
| 38 |
+ exitCode, err = execinCommand(container, nspid, flag.Args()[1:]) |
|
| 39 | 39 |
} else {
|
| 40 |
- exitCode, err = execCommand(container, os.Args[2:]) |
|
| 40 |
+ exitCode, err = execCommand(container, flag.Args()[1:]) |
|
| 41 | 41 |
} |
| 42 | 42 |
if err != nil {
|
| 43 | 43 |
log.Fatal(err) |
| 44 | 44 |
} |
| 45 | 45 |
os.Exit(exitCode) |
| 46 | 46 |
case "init": // this is executed inside of the namespace to setup the container |
| 47 |
- if argc < 3 {
|
|
| 47 |
+ if flag.NArg() < 2 {
|
|
| 48 | 48 |
log.Fatal(ErrWrongArguments) |
| 49 | 49 |
} |
| 50 |
- if err := initCommand(container, os.Args[2], os.Args[3:]); err != nil {
|
|
| 50 |
+ if err := initCommand(container, *console, flag.Args()[1:]); err != nil {
|
|
| 51 | 51 |
log.Fatal(err) |
| 52 | 52 |
} |
| 53 | 53 |
default: |
| 54 |
- log.Fatalf("command not supported for nsinit %s", os.Args[1])
|
|
| 54 |
+ log.Fatalf("command not supported for nsinit %s", flag.Arg(0))
|
|
| 55 | 55 |
} |
| 56 | 56 |
} |
| 57 | 57 |
|