Skip to content

cmd/run: add --preserve-fds command-line argument#1067

Merged
debarshiray merged 2 commits intocontainers:mainfrom
allisonkarlitskaya:preserve-fds
Nov 15, 2022
Merged

cmd/run: add --preserve-fds command-line argument#1067
debarshiray merged 2 commits intocontainers:mainfrom
allisonkarlitskaya:preserve-fds

Conversation

@allisonkarlitskaya
Copy link
Copy Markdown
Contributor

This mirrors the --preserve-fds argument of podman.

Fixes #1066

Welcome to "I've never written anything in Go before" hour :)

allisonkarlitskaya added a commit to allisonkarlitskaya/toolbox that referenced this pull request Jun 16, 2022
This mirrors the --preserve-fds argument of podman.

Fixes containers#1066

containers#1067

Signed-off-by: Allison Karlitskaya <[email protected]>
allisonkarlitskaya added a commit to allisonkarlitskaya/toolbox that referenced this pull request Jun 16, 2022
This mirrors the --preserve-fds argument of podman.

Fixes containers#1066

containers#1067

Signed-off-by: Allison Karlitskaya <[email protected]>
@softwarefactory-project-zuul
Copy link
Copy Markdown

Build succeeded.

✔️ unit-test SUCCESS in 6m 38s
✔️ system-test-fedora-rawhide SUCCESS in 10m 25s
✔️ system-test-fedora-36 SUCCESS in 10m 01s
✔️ system-test-fedora-35 SUCCESS in 10m 18s
✔️ system-test-fedora-34 SUCCESS in 10m 01s

@allisonkarlitskaya
Copy link
Copy Markdown
Contributor Author

@debarshiray ping?

Copy link
Copy Markdown
Member

@debarshiray debarshiray left a 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. :)

Comment thread src/cmd/run.go Outdated
Comment thread src/cmd/run.go Outdated
Comment thread src/cmd/run.go Outdated
Comment thread src/cmd/run.go Outdated
allisonkarlitskaya added a commit to allisonkarlitskaya/toolbox that referenced this pull request Nov 11, 2022
This mirrors the --preserve-fds argument of podman.

Fixes containers#1066

containers#1067

Signed-off-by: Allison Karlitskaya <[email protected]>
Copy link
Copy Markdown
Member

@debarshiray debarshiray left a 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!

Comment thread src/cmd/run.go Outdated

execArgs = append(execArgs, envOptions...)

if runFlags.preserveFDs != 0 {
Copy link
Copy Markdown
Member

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. :)

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

@debarshiray debarshiray Nov 14, 2022

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.

Comment thread src/cmd/run.go Outdated
@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

unit-test FAILURE in 8m 06s
unit-test-migration-path-for-coreos-toolbox FAILURE in 7m 41s
✔️ system-test-fedora-rawhide SUCCESS in 34m 44s
✔️ system-test-fedora-36 SUCCESS in 11m 56s
✔️ system-test-fedora-35 SUCCESS in 11m 28s

@allisonkarlitskaya
Copy link
Copy Markdown
Contributor Author

As per our conversation on IRC, I'll step back and let @debarshiray address the outstanding issues.

@debarshiray debarshiray force-pushed the preserve-fds branch 2 times, most recently from ce516aa to ed43d39 Compare November 14, 2022 19:33
@debarshiray
Copy link
Copy Markdown
Member

debarshiray commented Nov 14, 2022

As per our conversation on IRC, I'll step back and let @debarshiray address the outstanding issues.

I added some tests. It took longer than I expected because the test harness reserves two extra file descriptors.

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

✔️ unit-test SUCCESS in 7m 19s
unit-test-migration-path-for-coreos-toolbox RETRY_LIMIT in 7m 12s
✔️ system-test-fedora-rawhide SUCCESS in 29m 29s
✔️ system-test-fedora-36 SUCCESS in 9m 45s
✔️ system-test-fedora-35 SUCCESS in 10m 34s

@debarshiray
Copy link
Copy Markdown
Member

recheck

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

✔️ unit-test SUCCESS in 7m 40s
unit-test-migration-path-for-coreos-toolbox RETRY_LIMIT in 7m 35s
system-test-fedora-rawhide FAILURE in 28m 46s
✔️ system-test-fedora-36 SUCCESS in 9m 53s
✔️ system-test-fedora-35 SUCCESS in 10m 52s

@debarshiray
Copy link
Copy Markdown
Member

Damn:

#   Trying to pull quay.io/toolbox_tests/registry:latest...
#   Getting image source signatures
...
#   Error: writing blob: storing blob to file "/var/tmp/storage1659742604/3": happened during read: unexpected EOF

@debarshiray
Copy link
Copy Markdown
Member

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 <[email protected]>
@debarshiray
Copy link
Copy Markdown
Member

I suspect that unit-test-migration-path-for-coreos-toolbox was failing because I forgot to update the runCommand call in src/rootMigration.go and the code was failing to compile.

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

✔️ unit-test SUCCESS in 7m 06s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 7m 13s
system-test-fedora-rawhide FAILURE in 28m 46s
✔️ system-test-fedora-36 SUCCESS in 9m 33s
✔️ system-test-fedora-35 SUCCESS in 10m 31s

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build succeeded.

✔️ unit-test SUCCESS in 7m 09s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 7m 17s
✔️ system-test-fedora-rawhide SUCCESS in 27m 53s
✔️ system-test-fedora-36 SUCCESS in 9m 35s
✔️ system-test-fedora-35 SUCCESS in 10m 29s

@debarshiray debarshiray merged commit 9bf9f97 into containers:main Nov 15, 2022
@debarshiray
Copy link
Copy Markdown
Member

Thanks for working on this, @allisonkarlitskaya !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --forward-fd to toolbox run

2 participants