libpod: change function to accept ExecOptions

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2020-12-24 21:59:16 +01:00
parent 231c528a4d
commit 2a97639263
2 changed files with 7 additions and 6 deletions

View File

@ -387,7 +387,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
finalEnv = append(finalEnv, fmt.Sprintf("%s=%s", k, v)) finalEnv = append(finalEnv, fmt.Sprintf("%s=%s", k, v))
} }
processFile, err := prepareProcessExec(c, options.Cmd, finalEnv, options.Terminal, options.Cwd, options.User, sessionID) processFile, err := prepareProcessExec(c, options, finalEnv, sessionID)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -1185,26 +1185,26 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
// prepareProcessExec returns the path of the process.json used in runc exec -p // prepareProcessExec returns the path of the process.json used in runc exec -p
// caller is responsible to close the returned *os.File if needed. // caller is responsible to close the returned *os.File if needed.
func prepareProcessExec(c *Container, cmd, env []string, tty bool, cwd, user, sessionID string) (*os.File, error) { func prepareProcessExec(c *Container, options *ExecOptions, env []string, sessionID string) (*os.File, error) {
f, err := ioutil.TempFile(c.execBundlePath(sessionID), "exec-process-") f, err := ioutil.TempFile(c.execBundlePath(sessionID), "exec-process-")
if err != nil { if err != nil {
return nil, err return nil, err
} }
pspec := c.config.Spec.Process pspec := c.config.Spec.Process
pspec.SelinuxLabel = c.config.ProcessLabel pspec.SelinuxLabel = c.config.ProcessLabel
pspec.Args = cmd pspec.Args = options.Cmd
// We need to default this to false else it will inherit terminal as true // We need to default this to false else it will inherit terminal as true
// from the container. // from the container.
pspec.Terminal = false pspec.Terminal = false
if tty { if options.Terminal {
pspec.Terminal = true pspec.Terminal = true
} }
if len(env) > 0 { if len(env) > 0 {
pspec.Env = append(pspec.Env, env...) pspec.Env = append(pspec.Env, env...)
} }
if cwd != "" { if options.Cwd != "" {
pspec.Cwd = cwd pspec.Cwd = options.Cwd
} }
@ -1212,6 +1212,7 @@ func prepareProcessExec(c *Container, cmd, env []string, tty bool, cwd, user, se
var sgids []uint32 var sgids []uint32
// if the user is empty, we should inherit the user that the container is currently running with // if the user is empty, we should inherit the user that the container is currently running with
user := options.User
if user == "" { if user == "" {
user = c.config.User user = c.config.User
addGroups = c.config.Groups addGroups = c.config.Groups