From 05b7749fdc147b3f413b97b3a0adfc0cec91891c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 28 Apr 2015 01:59:17 -0400 Subject: feat: add chroot syscall --- src/unistd.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/unistd.rs') 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(path: &P) -> Result<()> { from_ffi(res) } +#[inline] +pub fn chroot(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}; -- cgit v1.2.3