mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Rework exec to enable splitting to retrieve exec PID
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #412 Approved by: baude
This commit is contained in:
@ -2,13 +2,11 @@ package libpod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/caps"
|
"github.com/docker/docker/daemon/caps"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectatomic/libpod/libpod/driver"
|
"github.com/projectatomic/libpod/libpod/driver"
|
||||||
@ -236,21 +234,8 @@ func (c *Container) Exec(tty, privileged bool, env, cmd []string, user string) e
|
|||||||
if privileged || c.config.Privileged {
|
if privileged || c.config.Privileged {
|
||||||
capList = caps.GetAllCapabilities()
|
capList = caps.GetAllCapabilities()
|
||||||
}
|
}
|
||||||
globalOpts := runcGlobalOptions{
|
|
||||||
log: c.LogPath(),
|
|
||||||
}
|
|
||||||
|
|
||||||
execOpts := runcExecOptions{
|
return c.runtime.ociRuntime.execContainer(c, cmd, tty, user, capList, env)
|
||||||
capAdd: capList,
|
|
||||||
pidFile: filepath.Join(c.state.RunDir, fmt.Sprintf("%s-execpid", stringid.GenerateNonCryptoID()[:12])),
|
|
||||||
env: env,
|
|
||||||
noNewPrivs: c.config.Spec.Process.NoNewPrivileges,
|
|
||||||
user: user,
|
|
||||||
cwd: c.config.Spec.Process.Cwd,
|
|
||||||
tty: tty,
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.runtime.ociRuntime.execContainer(c, cmd, globalOpts, execOpts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach attaches to a container
|
// Attach attaches to a container
|
||||||
|
@ -467,8 +467,54 @@ func (r *OCIRuntime) unpauseContainer(ctr *Container) error {
|
|||||||
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "resume", ctr.ID())
|
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "resume", ctr.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
//execContiner executes a command in a running container
|
// execContainer executes a command in a running container
|
||||||
func (r *OCIRuntime) execContainer(c *Container, cmd []string, globalOpts runcGlobalOptions, commandOpts runcExecOptions) error {
|
// TODO: Add --detach support
|
||||||
r.RuncExec(c, cmd, globalOpts, commandOpts)
|
// TODO: Convert to use conmon
|
||||||
return nil
|
// TODO: add --pid-file and use that to generate exec session tracking
|
||||||
|
func (r *OCIRuntime) execContainer(c *Container, cmd []string, tty bool, user string, capAdd, env []string) error {
|
||||||
|
args := []string{}
|
||||||
|
|
||||||
|
// TODO - should we maintain separate logpaths for exec sessions?
|
||||||
|
args = append(args, "--log", c.LogPath())
|
||||||
|
|
||||||
|
args = append(args, "exec")
|
||||||
|
|
||||||
|
args = append(args, "--cwd", c.config.Spec.Process.Cwd)
|
||||||
|
|
||||||
|
if tty {
|
||||||
|
args = append(args, "--tty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if user != "" {
|
||||||
|
args = append(args, "--user", user)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.config.Spec.Process.NoNewPrivileges {
|
||||||
|
args = append(args, "--no-new-privs")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, cap := range capAdd {
|
||||||
|
args = append(args, "--cap", cap)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, envVar := range env {
|
||||||
|
args = append(args, "--env", envVar)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append container ID and command
|
||||||
|
args = append(args, c.ID())
|
||||||
|
args = append(args, cmd...)
|
||||||
|
|
||||||
|
logrus.Debugf("Starting runtime %s with following arguments: %v", r.path, args)
|
||||||
|
|
||||||
|
execCmd := exec.Command(r.path, args...)
|
||||||
|
execCmd.Stdout = os.Stdout
|
||||||
|
execCmd.Stderr = os.Stderr
|
||||||
|
execCmd.Stdin = os.Stdin
|
||||||
|
|
||||||
|
if err := execCmd.Start(); err != nil {
|
||||||
|
return errors.Wrapf(err, "error starting exec command for container %s", c.ID())
|
||||||
|
}
|
||||||
|
|
||||||
|
return execCmd.Wait()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user