From 3a36f553a4409f8c050714a2f803dc3870426562 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Thu, 30 Nov 2017 10:43:35 +0100 Subject: [PATCH] container_exec: use process file with runc exec Signed-off-by: Antonio Murdaca --- server/container_exec.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/container_exec.go b/server/container_exec.go index 01d6e7c4..857e6e27 100644 --- a/server/container_exec.go +++ b/server/container_exec.go @@ -1,8 +1,10 @@ package server import ( + "encoding/json" "fmt" "io" + "io/ioutil" "os" "os/exec" "time" @@ -53,12 +55,29 @@ func (ss streamService) Exec(containerID string, cmd []string, stdin io.Reader, return fmt.Errorf("container is not created or running") } + f, err := ioutil.TempFile("", "exec-process") + if err != nil { + return err + } + defer os.RemoveAll(f.Name()) + + pspec := c.Spec().Process + pspec.Args = cmd + processJSON, err := json.Marshal(pspec) + if err != nil { + return err + } + + if err := ioutil.WriteFile(f.Name(), processJSON, 0644); err != nil { + return err + } + args := []string{"exec"} if tty { args = append(args, "-t") } + args = append(args, "-p", f.Name()) args = append(args, c.ID()) - args = append(args, cmd...) execCmd := exec.Command(ss.runtimeServer.Runtime().Path(c), args...) var cmdErr error if tty {