Skip to content

Add Command::resolve_in_parent_path #142035

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChrisDenton
Copy link
Member

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the resolve_in_parent_path method which forces Command to ignore PATH set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, chroot is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.

@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 4, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Member Author

Ah right, execvpe is a gnu extension. Bah.

@workingjubilee
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 4, 2025
@ChrisDenton
Copy link
Member Author

@bors2 try jobs=aarch64-apple,x86_64-msvc-*,dist-various-*

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

⌛ Trying commit 57a631f with merge 5b34fd8

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 5, 2025
Add `Command::resolve_in_parent_path`

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the `resolve_in_parent_path` method which forces `Command` to ignore `PATH` set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, `chroot` is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.
try-job: `aarch64-apple`
try-job: `x86_64-msvc-*`
try-job: `dist-various-*`
unsafe {
let name = program.to_bytes();
let mut buffer =
[const { mem::MaybeUninit::<u8>::uninit() }; libc::PATH_MAX as usize];
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'm aware that paths can be longer than PATH_MAX but I can't allocate here. I could allocate a buffer before fork but this is an experimental feature so I really want it to be as self-contained as possible so it can be removed or radically changed without too much disruption. Unsized locals would be another alternative...

In any case, if this feature ever approaches stabilisation, I can fix it then.

Comment on lines +1207 to +1208
/// On Unix the process is executed after fork and after setting up the rest of the new environment.
/// So if `chroot`, `uid`, `gid` or `groups` are used then the way `PATH` is interpreted may be changed.
Copy link
Member Author

Choose a reason for hiding this comment

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

So this was a point without agreement on the libs-api side. E.g. what should happen if chroot etc is set so the paths in PATH essentially point somewhere different. I decided to implement it the easy way for the sake of experimentation and hope that someone will bug me if they think we must do something different and explain their reasons.

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

💔 Test failed

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton ChrisDenton force-pushed the parent-path branch 3 times, most recently from f1663e5 to c8a279b Compare June 5, 2025 17:28
@ChrisDenton
Copy link
Member Author

@bors2 try jobs=aarch64-apple,x86_64-msvc-,dist-various-

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

⌛ Trying commit c8a279b with merge 3432b11

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 5, 2025
Add `Command::resolve_in_parent_path`

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the `resolve_in_parent_path` method which forces `Command` to ignore `PATH` set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, `chroot` is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.
try-job: aarch64-apple
try-job: x86_64-msvc-*
try-job: dist-various-*
@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

💔 Test failed

@ChrisDenton
Copy link
Member Author

@bors2 try jobs=x86_64-msvc-*,dist-various-*

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

⌛ Trying commit c8a279b with merge 0f9a1f9

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 5, 2025
Add `Command::resolve_in_parent_path`

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the `resolve_in_parent_path` method which forces `Command` to ignore `PATH` set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, `chroot` is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.
try-job: `x86_64-msvc-*`
try-job: `dist-various-*`
@ChrisDenton
Copy link
Member Author

@bors2 try jobs=x86_64-msvc-*,dist-various-*

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

❗ A try build is currently in progress. You can cancel it using @bors2 try cancel.

@ChrisDenton
Copy link
Member Author

@bors2 try cancel

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

Try build cancelled. Cancelled workflows:

@ChrisDenton
Copy link
Member Author

@bors2 try jobs=x86_64-msvc-*,dist-various-*

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

⌛ Trying commit 5a42e16 with merge c6b4698

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 5, 2025
Add `Command::resolve_in_parent_path`

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the `resolve_in_parent_path` method which forces `Command` to ignore `PATH` set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, `chroot` is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.
try-job: `x86_64-msvc-*`
try-job: `dist-various-*`
@ChrisDenton
Copy link
Member Author

ChrisDenton commented Jun 5, 2025

So it turns out the apple failures (after the first) where all due to a try-job issue and not genuine failures. That's good because I was deeply confused about why it was failing. That's bad because I did waste time trying to figure it out.

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

💔 Test failed

@ChrisDenton
Copy link
Member Author

@bors2 try jobs=x86_64-msvc-*,dist-various-*

@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

⌛ Trying commit f892c4c with merge b895bfd

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 5, 2025
Add `Command::resolve_in_parent_path`

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the `resolve_in_parent_path` method which forces `Command` to ignore `PATH` set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, `chroot` is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.
try-job: `x86_64-msvc-*`
try-job: `dist-various-*`
@ChrisDenton
Copy link
Member Author

I'm basically just fixing the unimplemented platforms at this point so I think this is ready for review

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 5, 2025
@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

💔 Test failed

@ChrisDenton
Copy link
Member Author

@bors2 try jobs=x86_64-msvc-*,dist-various-*

rust-bors bot added a commit that referenced this pull request Jun 5, 2025
Add `Command::resolve_in_parent_path`

This is part of #141976 (ACP: rust-lang/libs-team#591). libs-api could not come to a consensus on what the final API should look like so they've agreed to experiment with a few different approaches.

This PR just implements the `resolve_in_parent_path` method which forces `Command` to ignore `PATH` set on the child for the purposes of resolving the executable. There was no consensus on what should happen if, for example, `chroot` is set (which can change the meaning of paths) so for now I've just done the easy thing. Figuring out the correct behaviour here will need to be done before this is considered for stabilisation but hopefully having it on nightly will nudge people in to giving their opinions.
try-job: `x86_64-msvc-*`
try-job: `dist-various-*`
@rust-bors
Copy link

rust-bors bot commented Jun 5, 2025

⌛ Trying commit ee32374 with merge e211489

To cancel the try build, run the command @bors2 try cancel.

@rust-bors
Copy link

rust-bors bot commented Jun 6, 2025

☀️ Try build successful (CI)
Build commit: e211489 (e2114896a1c09ea2c35cbddba98ee4c816032eea)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants