Skip to content

Commit 4440881

Browse files
authored
Add a simple example program that uses pivot_root. (#1117)
Add an example program that uses `pivot_root`, similar to the common shell utility.
1 parent b0d3681 commit 4440881

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/pivot_root.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! A wrapper around `rustix::fs::pivot_root`.
2+
3+
#[cfg(all(target_os = "linux", feature = "fs", feature = "process"))]
4+
fn main() -> rustix::io::Result<()> {
5+
let mut args = std::env::args();
6+
if args.len() != 3 {
7+
eprintln!("Usage: {} new_root put_old", args.next().unwrap());
8+
std::process::exit(1);
9+
}
10+
11+
let _argv0 = args.next().unwrap();
12+
let new_root = args.next().unwrap();
13+
let put_old = args.next().unwrap();
14+
15+
rustix::process::pivot_root(new_root, put_old)?;
16+
17+
Ok(())
18+
}
19+
20+
#[cfg(any(
21+
not(target_os = "linux"),
22+
not(feature = "fs"),
23+
not(feature = "process")
24+
))]
25+
fn main() -> Result<(), &'static str> {
26+
Err("This example requires --features=fs,process and is only supported on Linux.")
27+
}

0 commit comments

Comments
 (0)