Revert "container_exec: fix terminal true process json"

This reverts commit afeab27a36.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2018-01-13 17:05:05 +01:00
parent d0e0303921
commit 67ddc911e5
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 39 additions and 30 deletions

View file

@ -423,6 +423,15 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp
os.RemoveAll(logPath)
}()
f, err := ioutil.TempFile("", "exec-sync-process")
if err != nil {
return nil, ExecSyncError{
ExitCode: -1,
Err: err,
}
}
defer os.RemoveAll(f.Name())
var args []string
args = append(args, "-c", c.id)
args = append(args, "-r", r.Path(c))
@ -438,16 +447,24 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp
args = append(args, "-l", logPath)
args = append(args, "--socket-dir-path", ContainerAttachSocketDir)
processFile, err := PrepareProcessExec(c, command, false)
pspec := c.Spec().Process
pspec.Args = command
processJSON, err := json.Marshal(pspec)
if err != nil {
return nil, ExecSyncError{
ExitCode: -1,
Err: err,
}
}
defer os.RemoveAll(processFile.Name())
args = append(args, "--exec-process-spec", processFile.Name())
if err := ioutil.WriteFile(f.Name(), processJSON, 0644); err != nil {
return nil, ExecSyncError{
ExitCode: -1,
Err: err,
}
}
args = append(args, "--exec-process-spec", f.Name())
cmd := exec.Command(r.conmonPath, args...)
@ -755,27 +772,3 @@ func (r *Runtime) UnpauseContainer(c *Container) error {
_, err := utils.ExecCmd(r.Path(c), "resume", c.id)
return err
}
// PrepareProcessExec returns the path of the process.json used in runc exec -p
// caller is responsible to close the returned *os.File if needed.
func PrepareProcessExec(c *Container, cmd []string, tty bool) (*os.File, error) {
f, err := ioutil.TempFile("", "exec-process-")
if err != nil {
return nil, err
}
pspec := c.Spec().Process
pspec.Args = cmd
if tty {
pspec.Terminal = true
}
processJSON, err := json.Marshal(pspec)
if err != nil {
return nil, err
}
if err := ioutil.WriteFile(f.Name(), processJSON, 0644); err != nil {
return nil, err
}
return f, nil
}

View file

@ -1,8 +1,10 @@
package server
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"time"
@ -53,14 +55,28 @@ func (ss streamService) Exec(containerID string, cmd []string, stdin io.Reader,
return fmt.Errorf("container is not created or running")
}
processFile, err := oci.PrepareProcessExec(c, cmd, tty)
f, err := ioutil.TempFile("", "exec-process")
if err != nil {
return err
}
defer os.RemoveAll(processFile.Name())
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 = append(args, "--process", processFile.Name())
if tty {
args = append(args, "-t")
}
args = append(args, "-p", f.Name())
args = append(args, c.ID())
execCmd := exec.Command(ss.runtimeServer.Runtime().Path(c), args...)
var cmdErr error