diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-02-25 11:44:06 +0100 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-03-02 11:45:42 +0100 |
commit | 0b34327ad40e04861dac7f73870d87633a5c637e (patch) | |
tree | f7f601f616e34bd749a39f46bec66da4f0abaaf0 /libpod/oci.go | |
parent | 9adcda73892fa0a33cbdf971ad97cf079e8e425f (diff) | |
download | podman-0b34327ad40e04861dac7f73870d87633a5c637e.tar.gz podman-0b34327ad40e04861dac7f73870d87633a5c637e.tar.bz2 podman-0b34327ad40e04861dac7f73870d87633a5c637e.zip |
exec: support --preserve-fds
Allow to pass additional FDs to the process being executed.
Closes: https://github.com/containers/libpod/issues/2372
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod/oci.go')
-rw-r--r-- | libpod/oci.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libpod/oci.go b/libpod/oci.go index 2b3cc5db5..2cbf25699 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -733,7 +733,7 @@ func (r *OCIRuntime) unpauseContainer(ctr *Container) error { // TODO: Add --detach support // TODO: Convert to use conmon // TODO: add --pid-file and use that to generate exec session tracking -func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty bool, cwd, user, sessionID string, streams *AttachStreams) (*exec.Cmd, error) { +func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty bool, cwd, user, sessionID string, streams *AttachStreams, preserveFDs int) (*exec.Cmd, error) { if len(cmd) == 0 { return nil, errors.Wrapf(ErrInvalidArg, "must provide a command to execute") } @@ -770,6 +770,9 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty args = append(args, "--user", user) } + if preserveFDs > 0 { + args = append(args, fmt.Sprintf("--preserve-fds=%d", preserveFDs)) + } if c.config.Spec.Process.NoNewPrivileges { args = append(args, "--no-new-privs") } @@ -806,6 +809,14 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty return nil, errors.Wrapf(err, "cannot start container %s", c.ID()) } + if preserveFDs > 0 { + for fd := 3; fd < 3+preserveFDs; fd++ { + // These fds were passed down to the runtime. Close them + // and not interfere + os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd)).Close() + } + } + return execCmd, nil } |