Skip to content

Commit

Permalink
Fix runin code for nsinit
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
  • Loading branch information
Michael Crosby authored and vishh committed Jul 22, 2014
1 parent bb85e2b commit b2337e4
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions nsinit/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,45 @@ var execCommand = cli.Command{
}

func execAction(context *cli.Context) {
var exitCode int

container, err := loadContainer()
if err != nil {
log.Fatal(err)
}

state, err := libcontainer.GetState(dataPath)
if err != nil && !os.IsNotExist(err) {
log.Fatalf("unable to read state.json: %s", err)
}

if state != nil {
exitCode, err = runIn(container, state, []string(context.Args()))
} else {
exitCode, err = startContainer(container, dataPath, []string(context.Args()))
}

if err != nil {
log.Fatalf("failed to exec: %s", err)
}

os.Exit(exitCode)
}

func runIn(container *libcontainer.Config, state *libcontainer.State, args []string) (int, error) {
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)
sigc = make(chan os.Signal, 10)
)

signal.Notify(sigc)

container, err := loadContainer()
if err != nil {
log.Fatal(err)
}

state, err := libcontainer.GetState(dataPath)
if err != nil && !os.IsNotExist(err) {
log.Fatalf("unable to read state.json: %s", err)
}

if container.Tty {
stdin = nil
stdout = nil
Expand Down Expand Up @@ -83,17 +98,7 @@ func execAction(context *cli.Context) {
}()
}

if state != nil {
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()))
}

if err != nil {
log.Fatalf("failed to exec: %s", err)
}

os.Exit(exitCode)
return namespaces.RunIn(container, state, args, os.Args[0], stdin, stdout, stderr, console, startCallback)
}

// startContainer starts the container. Returns the exit status or -1 and an
Expand Down

0 comments on commit b2337e4

Please sign in to comment.