Return ContainerExecCreateResponse from container exec start API endpoint, Fixes #11613

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca
2015-03-24 00:41:54 +01:00
parent 92f9e2d395
commit 0c3d2f6f96
3 changed files with 28 additions and 7 deletions
+13 -4
View File
@@ -1155,10 +1155,11 @@ func postContainerExecCreate(eng *engine.Engine, version version.Version, w http
return nil
}
var (
out engine.Env
name = vars["name"]
job = eng.Job("execCreate", name)
stdoutBuffer = bytes.NewBuffer(nil)
outWarnings []string
warnings = bytes.NewBuffer(nil)
)
if err := job.DecodeEnv(r.Body); err != nil {
@@ -1166,15 +1167,23 @@ func postContainerExecCreate(eng *engine.Engine, version version.Version, w http
}
job.Stdout.Add(stdoutBuffer)
// Read warnings from stderr
job.Stderr.Add(warnings)
// Register an instance of Exec in container.
if err := job.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error setting up exec command in container %s: %s\n", name, err)
return err
}
// Return the ID
out.Set("Id", engine.Tail(stdoutBuffer, 1))
// Parse warnings from stderr
scanner := bufio.NewScanner(warnings)
for scanner.Scan() {
outWarnings = append(outWarnings, scanner.Text())
}
return writeJSONEnv(w, http.StatusCreated, out)
return writeJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{
ID: engine.Tail(stdoutBuffer, 1),
Warnings: outWarnings,
})
}
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.