diff options
author | Qingping Hou <dave2008713@gmail.com> | 2015-04-28 01:59:17 -0400 |
---|---|---|
committer | Qingping Hou <dave2008713@gmail.com> | 2015-04-28 01:59:17 -0400 |
commit | 05b7749fdc147b3f413b97b3a0adfc0cec91891c (patch) | |
tree | b307dab8bcb0f03590326f07e0e0e07d480c50c9 /src/unistd.rs | |
parent | 8127b4dd6d37ae028a31c013b7d5758d66362b04 (diff) | |
download | nix-05b7749fdc147b3f413b97b3a0adfc0cec91891c.zip |
feat: add chroot syscall
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 6d7e2982..354e46db 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -41,6 +41,10 @@ mod ffi { // gets the hostname // doc: http://man7.org/linux/man-pages/man2/gethostname.2.html pub fn sethostname(name: *const c_char, len: size_t) -> c_int; + + // change root directory + // doc: http://man7.org/linux/man-pages/man2/gethostname.2.html + pub fn chroot(path: *const c_char) -> c_int; } } @@ -293,6 +297,19 @@ pub fn unlink<P: ?Sized + NixPath>(path: &P) -> Result<()> { from_ffi(res) } +#[inline] +pub fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<()> { + let res = try!(path.with_nix_path(|osstr| { + unsafe { ffi::chroot(osstr.as_ext_str()) } + })); + + if res != 0 { + return Err(Error::Sys(Errno::last())); + } + + Ok(()) +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux { use sys::syscall::{syscall, SYSPIVOTROOT}; |