Skip to content
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

exec: support --preserve-fds #2426

Merged

Conversation

giuseppe
Copy link
Member

Allow to pass additional FDs to the process being executed.

Closes: #2372

Depends on: opencontainers/runc#1995

Signed-off-by: Giuseppe Scrivano gscrivan@redhat.com

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M labels Feb 25, 2019
@@ -47,6 +49,7 @@ func init() {
flags.BoolVarP(&execCommand.Tty, "tty", "t", false, "Allocate a pseudo-TTY. The default is false")
flags.StringVarP(&execCommand.User, "user", "u", "", "Sets the username or UID used and optionally the groupname or GID for the specified command")

flags.IntVar(&execCommand.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container")
Copy link
Member

Choose a reason for hiding this comment

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

I think flatpak passes in the specific numbers of the FDs in question, and allows the flag to be specified multiple times. Not sure if compatibility with them is important here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should rather look at what runc already does, it supports --preserve-fds, but only for create/run at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

If this is runc's behavior, matching it SGTM

@@ -82,11 +85,34 @@ func execCmd(c *cliconfig.ExecValues) error {
return errors.Wrapf(err, "unable to exec into %s", args[0])
}

if c.PreserveFDs > 0 {
entries, err := ioutil.ReadDir("/proc/self/fd")
Copy link
Member

Choose a reason for hiding this comment

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

Can you use os.NewFile here, and directly pass the FD number? The docs say it will ensure a file wrapping a valid FD is returned, so we can use it to check if the FD in question is present

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it means it checks only that once casted it is not <0:

    fmt.Printf("got: %v\n", os.NewFile(1, "f1"))
    fmt.Printf("got: %v\n", os.NewFile(100000000000, "f2"))
    fmt.Printf("got: %v\n", os.NewFile(9223372036854775808, "f3"))

I get:

got: &{0xc00006c180}
got: &{0xc00006c1e0}
got: <nil>

Copy link
Member

Choose a reason for hiding this comment

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

Ah, so it's fake checking and the stdlib docs are lying, then.

It would have been neater than checking /proc, but if we can't do it this works fine.

libpod/oci.go Show resolved Hide resolved
@giuseppe
Copy link
Member Author

/retest

@giuseppe giuseppe closed this Feb 26, 2019
@giuseppe giuseppe deleted the exec-preserve-fds branch February 26, 2019 10:29
@rhatdan
Copy link
Member

rhatdan commented Feb 26, 2019

Do we no longer need this?

@giuseppe
Copy link
Member Author

we do, not sure how it got closed

@giuseppe giuseppe restored the exec-preserve-fds branch February 26, 2019 13:41
@giuseppe giuseppe reopened this Feb 26, 2019
@rhatdan
Copy link
Member

rhatdan commented Feb 26, 2019

@giuseppe Does this require a new version of runc?
I think this should go in after 1.1 is released.

@giuseppe
Copy link
Member Author

@giuseppe Does this require a new version of runc?
I think this should go in after 1.1 is released.

yes, the PR implementing it was merged yesterday

@rhatdan
Copy link
Member

rhatdan commented Feb 26, 2019

Ok so lets wait for v1.1 is shipped and then we can put this in master, and start moving runc through the process of getting it released.

@mheon
Copy link
Member

mheon commented Feb 27, 2019

Needs to update RELEASE_NOTES.md with changes

@mheon
Copy link
Member

mheon commented Feb 27, 2019

Nevermind the noise, don't bother with release notes

@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #2487) made this pull request unmergeable. Please resolve the merge conflicts.

@mheon
Copy link
Member

mheon commented Mar 2, 2019

I'm ready to merge this once the conflicts are fixed

Allow to pass additional FDs to the process being executed.

Closes: containers#2372

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe
Copy link
Member Author

giuseppe commented Mar 2, 2019

rebased

@rhatdan
Copy link
Member

rhatdan commented Mar 2, 2019

LGTM

@giuseppe
Copy link
Member Author

giuseppe commented Mar 5, 2019

@mheon is this good to go?

@rhatdan
Copy link
Member

rhatdan commented Mar 5, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 5, 2019
@openshift-merge-robot openshift-merge-robot merged commit 85b1167 into containers:master Mar 5, 2019
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants