Add std::os::unix::fs::chroot to change the root directory of the current process#84716
Add std::os::unix::fs::chroot to change the root directory of the current process#84716bors merged 1 commit intorust-lang:masterfrom
Conversation
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
|
@bors r+ |
|
📌 Commit 2fb2f0b has been approved by |
This comment has been minimized.
This comment has been minimized.
Add std::os::unix::fs::chroot to change the root directory of the current process This is a straightforward wrapper that uses the existing helpers for C string handling and errno handling. Having this available is convenient for UNIX utility programs written in Rust, and avoids having to call the unsafe `libc::chroot` directly and handle errors manually, in a program that may otherwise be entirely safe code.
|
Fixed the doc link. @bors r=dtolnay rollup |
|
📌 Commit 3b414c3 has been approved by |
| /// This typically requires privileges, such as root or a specific capability. | ||
| /// | ||
| /// This does not change the current working directory; you should call | ||
| /// [`std::env::set_current_dir`][`crate::env::set_current_dir`] afterwards. |
There was a problem hiding this comment.
Adding extern crate self as std; in std's lib.rs would avoid having to do the link target explicitly here (and definitely elsewhere too).
There was a problem hiding this comment.
According to @jyn514, doing that currently produces an ICE.
There was a problem hiding this comment.
This is #73445. I haven't tried it in a while, it may work now.
There was a problem hiding this comment.
Also, you can shorten a bit like so:
| /// [`std::env::set_current_dir`][`crate::env::set_current_dir`] afterwards. | |
| /// [`std::env::set_current_dir`](crate::env::set_current_dir) afterwards. |
There was a problem hiding this comment.
If you go the extern crate route, you might want to do
#[cfg(doc)]
extern crate self as std;to ensure it's only used for docs.
There was a problem hiding this comment.
@camelid that will break any links that are re-exported, cfg(doc) isn't set for dependencies.
There was a problem hiding this comment.
I haven't tried it in a while, it may work now.
Just tried it, extern crate self as core works but not extern crate self as std (#84755, #73445 (comment)).
This comment has been minimized.
This comment has been minimized.
Add std::os::unix::fs::chroot to change the root directory of the current process This is a straightforward wrapper that uses the existing helpers for C string handling and errno handling. Having this available is convenient for UNIX utility programs written in Rust, and avoids having to call the unsafe `libc::chroot` directly and handle errors manually, in a program that may otherwise be entirely safe code.
|
⌛ Testing commit eda658dc7c95c69e8c1f7191b0ba7bebb6e6be2e with merge fe71c7f6e0f60886eff3b39268916552115b74e1... |
This comment has been minimized.
This comment has been minimized.
|
💔 Test failed - checks-actions |
|
Well, that's interesting. Either Fuchsia doesn't have cc @tmandry for Fuchsia. |
|
The answer appears to be that Fuchsia doesn't have chroot. I'll add a |
…rent process This is a straightforward wrapper that uses the existing helpers for C string handling and errno handling. Having this available is convenient for UNIX utility programs written in Rust, and avoids having to call the unsafe `libc::chroot` directly and handle errors manually, in a program that may otherwise be entirely safe code.
|
@bors try |
|
⌛ Trying commit ffb874a with merge 7ede84235ed7c851bb5bc27e1f7d6f438d6b78d5... |
|
☀️ Try build successful - checks-actions |
|
@bors r=dtolnay rollup=never |
|
📌 Commit ffb874a has been approved by |
|
☀️ Test successful - checks-actions |
Fix `vxworks` Some PRs made the `vxworks` target not build anymore. This PR fixes that: - rust-lang#82973: copy `ExitStatusError` implementation from `unix`. - rust-lang#84716: no `libc::chroot` available on `vxworks`, so for now don't implement `os::unix::fs::chroot`.
This is a straightforward wrapper that uses the existing helpers for C
string handling and errno handling.
Having this available is convenient for UNIX utility programs written in
Rust, and avoids having to call the unsafe
libc::chrootdirectly andhandle errors manually, in a program that may otherwise be entirely safe
code.