From e69a2729d2e354593b5329d7a62559321daab2ef Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 27 Mar 2014 18:26:42 -0700 Subject: [PATCH] beam/examples/beamsh: support for background commands with '&' terminator Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: 6e0a156d9086300a34b0e1f441dd5150dde57be1 Component: engine --- .../engine/pkg/beam/examples/beamsh/beamsh.go | 14 ++++++++++++-- components/engine/pkg/dockerscript/dockerscript.go | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/engine/pkg/beam/examples/beamsh/beamsh.go b/components/engine/pkg/beam/examples/beamsh/beamsh.go index fac986e14e..4234e9d988 100644 --- a/components/engine/pkg/beam/examples/beamsh/beamsh.go +++ b/components/engine/pkg/beam/examples/beamsh/beamsh.go @@ -136,9 +136,19 @@ func scriptString(script []*dockerscript.Command) string { func executeScript(client *net.UnixConn, script []*dockerscript.Command) error { Debugf("executeScript(%s)\n", scriptString(script)) defer Debugf("executeScript(%s) DONE\n", scriptString(script)) + var background sync.WaitGroup + defer background.Wait() for _, cmd := range script { - if err := executeCommand(client, cmd); err != nil { - return err + if cmd.Background { + background.Add(1) + go func(client *net.UnixConn, cmd *dockerscript.Command) { + executeCommand(client, cmd) + background.Done() + }(client, cmd) + } else { + if err := executeCommand(client, cmd); err != nil { + return err + } } } return nil diff --git a/components/engine/pkg/dockerscript/dockerscript.go b/components/engine/pkg/dockerscript/dockerscript.go index ba16b2f523..582f1fdf92 100644 --- a/components/engine/pkg/dockerscript/dockerscript.go +++ b/components/engine/pkg/dockerscript/dockerscript.go @@ -10,6 +10,7 @@ import ( type Command struct { Args []string Children []*Command + Background bool } type Scanner struct { @@ -72,7 +73,7 @@ func parseArgs(s *Scanner) ([]string, rune, error) { return args, tok, nil } if !s.commentLine { - if text == "{" || text == "}" || text == "\n" || text == "\r" || text == ";" { + if text == "{" || text == "}" || text == "\n" || text == "\r" || text == ";" || text == "&" { return args, tok, nil } args = append(args, text) @@ -106,6 +107,8 @@ func parse(s *Scanner, opener string) (expr []*Command, err error) { cmd.Children = children } else if afterArgs == "}" && opener != "{" { return nil, fmt.Errorf("unexpected end of block '}'") + } else if afterArgs == "&" { + cmd.Background = true } if len(cmd.Args) > 0 || len(cmd.Children) > 0 { expr = append(expr, cmd)