-
Notifications
You must be signed in to change notification settings - Fork 236
cmd/run: add --preserve-fds
command-line argument
#1067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This mirrors the --preserve-fds argument of podman. Fixes containers#1066 containers#1067 Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
212eae3
to
1ee68e6
Compare
This mirrors the --preserve-fds argument of podman. Fixes containers#1066 containers#1067 Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
1ee68e6
to
22f753a
Compare
Build succeeded. ✔️ unit-test SUCCESS in 6m 38s |
@debarshiray ping? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @allisonkarlitskaya ! My apologies - it fell off my radar.
It looks mostly good to me. It will need some rebasing, but I will take care of it, because right now I am staring at the need for podman exec --preserve-fds ...
myself for the internal use of Toolbx. :)
22f753a
to
518056b
Compare
This mirrors the --preserve-fds argument of podman. Fixes containers#1066 containers#1067 Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
src/cmd/run.go
Outdated
@@ -481,6 +488,10 @@ func constructExecArgs(container string, | |||
|
|||
execArgs = append(execArgs, envOptions...) | |||
|
|||
if runFlags.preserveFDs != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that this should be > 0
because that's also what Podman uses. Otherwise, we will only error out later from podman exec ...
itself:
$ toolbox run --preserve-fds -12 true
Error: failed to invoke 'podman exec' in container fedora-toolbox-36
$ echo $?
125
This makes me wonder if we should be using an unsigned integer flag. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that newer versions of Podman do use an unsigned integer flag.
It's not obvious from the commit message, but that's where it changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn! Converting an unsigned integer to a string is surprisingly annoying. :)
strconv.Itoa takes a signed int
, which would require a cast, and there's no unsigned counterpart. There's strconv.FormatUint which takes an unsigned uint64
, which is better, but would still require a cast.
So, fmt.Sprint it is, if we want to avoid the casting. It's a bit more expensive than the other two functions, but we don't have to worry about it unless it's proven to be a performance bottle neck.
Build failed. ❌ unit-test FAILURE in 8m 06s |
As per our conversation on IRC, I'll step back and let @debarshiray address the outstanding issues. |
ce516aa
to
ed43d39
Compare
I added some tests. It took longer than I expected because the test harness reserves two extra file descriptors. |
Build failed. ✔️ unit-test SUCCESS in 7m 19s |
recheck |
Build failed. ✔️ unit-test SUCCESS in 7m 40s |
Damn:
|
recheck |
This mirrors the --preserve-fds option of Podman. Converting an unsigned 'uint', which is what Podman uses for its --preserve-fds option, to a string is surprisingly annoying. strconv.Itoa [1] takes a signed 'int', which would require a cast, and there's no unsigned counterpart. There's strconv.FormatUint [2] which takes an unsigned 'uint64', which is better, but would still require a cast. So, fmt.Sprint [3] it is, if the cast is to be avoided. It's more expensive than the other two functions, but there's no need to worry unless it's proven to be a performance bottle neck. Some changes by Debarshi Ray. [1] https://pkg.go.dev/strconv#Itoa [2] https://pkg.go.dev/strconv#FormatUint [3] https://pkg.go.dev/fmt#Sprint containers#1066 Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
ed43d39
to
11cd1b2
Compare
I suspect that |
Build failed. ✔️ unit-test SUCCESS in 7m 06s |
Note that file descriptors 3 and 4 are reserved by Bats. The former is used for adding custom text to the Test Anything Protocol (or TAP) stream [1] and the latter for tracing [2]. [1] https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs https://bats-core.readthedocs.io/en/stable/writing-tests.html#printing-to-the-terminal [2] Bats commit 635700cd2282b754 bats-core/bats-core#467 bats-core/bats-core#488 containers#1066
11cd1b2
to
9bf9f97
Compare
Build succeeded. ✔️ unit-test SUCCESS in 7m 09s |
Thanks for working on this, @allisonkarlitskaya ! |
This mirrors the
--preserve-fds
argument of podman.Fixes #1066
Welcome to "I've never written anything in Go before" hour :)