container_exec: use process file with runc exec

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-11-30 10:43:35 +01:00
parent 6faef13293
commit c6f68f1bf1
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9

View file

@ -1,8 +1,10 @@
package server package server
import ( import (
"encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"time" "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") 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"} args := []string{"exec"}
if tty { if tty {
args = append(args, "-t") args = append(args, "-t")
} }
args = append(args, "-p", f.Name())
args = append(args, c.ID()) args = append(args, c.ID())
args = append(args, cmd...)
execCmd := exec.Command(ss.runtimeServer.Runtime().Path(c), args...) execCmd := exec.Command(ss.runtimeServer.Runtime().Path(c), args...)
var cmdErr error var cmdErr error
if tty { if tty {