From 70bec49127cac36aeaa140bfa2ae30eebca6f768 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 10 Aug 2024 13:25:56 -0600 Subject: [PATCH] libopenbsd.rs(3): fixes API for unveil(2) --- src/libopenbsd.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libopenbsd.rs b/src/libopenbsd.rs index 7d98d10..c16c51c 100644 --- a/src/libopenbsd.rs +++ b/src/libopenbsd.rs @@ -17,7 +17,7 @@ */ use std::{ - ffi::{ CString, c_int }, + ffi::CString, io::Error, ptr::null, }; @@ -76,7 +76,10 @@ impl UnveilPerms { } } -pub fn unveil(path: Option<&str>, permissions: Option) -> c_int { +pub fn unveil( + path: Option<&str>, + permissions: Option, +) -> Result<(), Error> { let path_c = path.map(CString::new).map(Result::unwrap); let arg1 = path_c.map(|p| p.into_raw() as *const i8).unwrap_or(null()); @@ -84,5 +87,11 @@ pub fn unveil(path: Option<&str>, permissions: Option) -> c_int { .map(|p| p.0.into_raw() as *const i8) .unwrap_or(null()); - unsafe { openbsd::unveil(arg1, arg2) } + unsafe { + match openbsd::unveil(arg1, arg2) { + -1 => Err(Error::from_raw_os_error(*openbsd::__errno())), + 0 => Ok(()), + _ => panic!(), /* unreachable */ + } + } }