Skip to content

Commit

Permalink
'nsinit exec' now uses namespaces.RunIn instead of namespaces.ExecIn.
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
  • Loading branch information
vishh committed Jul 22, 2014
1 parent 1f28287 commit bb85e2b
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions nsinit/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ var execCommand = cli.Command{
}

func execAction(context *cli.Context) {
var exitCode int
var (
exitCode int
master *os.File
console string
err error

stdin = os.Stdin
stdout = os.Stdout
stderr = os.Stderr
sigc = make(chan os.Signal, 10)
)

signal.Notify(sigc)

container, err := loadContainer()
if err != nil {
Expand All @@ -35,8 +47,44 @@ func execAction(context *cli.Context) {
log.Fatalf("unable to read state.json: %s", err)
}

if container.Tty {
stdin = nil
stdout = nil
stderr = nil

master, console, err = consolepkg.CreateMasterAndConsole()
if err != nil {
log.Fatal(err)
}

go io.Copy(master, os.Stdin)
go io.Copy(os.Stdout, master)

state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
log.Fatal(err)
}

defer term.RestoreTerminal(os.Stdin.Fd(), state)
}

startCallback := func(cmd *exec.Cmd) {
go func() {
resizeTty(master)

for sig := range sigc {
switch sig {
case syscall.SIGWINCH:
resizeTty(master)
default:
cmd.Process.Signal(sig)
}
}
}()
}

if state != nil {
err = namespaces.ExecIn(container, state, []string(context.Args()))
exitCode, err = namespaces.RunIn(container, state, []string(context.Args()), os.Args[0], stdin, stdout, stderr, console, startCallback)
} else {
exitCode, err = startContainer(container, dataPath, []string(context.Args()))
}
Expand Down

0 comments on commit bb85e2b

Please sign in to comment.