Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ following will output a list of processes running in the container:
Usage: "disable the use of the subreaper used to reap reparented processes",
Hidden: true,
},
cli.IntFlag{
Name: "preserve-fds",
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
},
},
Action: func(context *cli.Context) error {
if err := checkArgs(context, 1, minArgs); err != nil {
Expand Down Expand Up @@ -141,6 +145,7 @@ func execProcess(context *cli.Context) (int, error) {
pidFile: context.String("pid-file"),
action: CT_ACT_RUN,
init: false,
preserveFDs: context.Int("preserve-fds"),
}
return r.run(p)
}
Expand Down
1 change: 1 addition & 0 deletions man/runc-exec.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ following will output a list of processes running in the container:
--no-new-privs set the no new privileges value for the process
--cap value, -c value add a capability to the bounding set for the process
--no-subreaper disable the use of the subreaper used to reap reparented processes
--preserve-fds value pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total) (default: 0)
11 changes: 11 additions & 0 deletions tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,14 @@ function teardown() {

[[ ${output} == "uid=1000 gid=1000 groups=99(nogroup),100(users)" ]]
}

@test "runc exec --preserve-fds" {
# run busybox detached
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]

run bash -c "cat hello > preserve-fds.test; exec 3<preserve-fds.test; $RUNC --log /proc/self/fd/2 --root $ROOT exec --preserve-fds=1 test_busybox cat /proc/self/fd/3"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't understand is why cat hello is not failing. There is no such file named hello.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the error is just ignored but the file is still created by the shell. I guess it had to be echo but too long ago to remember :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, yes, cat hello should fail and this is ignored by bash since it does not run with set -e.

What I don't understand is how the check below (that checks that $output contains hello works at all.

Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuseppe pointed out that cat hello produces the message like cat: hello: no such file or directory, and thus the check for hello in the $output succeeds!

[ "$status" -eq 0 ]

[[ "${output}" == *"hello"* ]]
}