Function std::os::unix::fs::chroot
pub fn chroot<P: AsRef<Path>>(dir: P) -> Result<()>
This is supported on Unix only.
Change the root directory of the current process to the specified path.
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
afterwards.
Examples
use std::os::unix::fs; fn main() -> std::io::Result<()> { fs::chroot("/sandbox")?; std::env::set_current_dir("/")?; // continue working in sandbox Ok(()) }
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/os/unix/fs/fn.chroot.html