From 17890eafb930d9652e9f94a4a66521c2b389dea6 Mon Sep 17 00:00:00 2001 From: Marco Conte Date: Wed, 18 Dec 2019 08:40:47 +0000 Subject: [PATCH] fix return value for setfsuid and setfsgid --- src/unistd.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/unistd.rs b/src/unistd.rs index cfb2e8d626..a4c0b405b2 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1398,26 +1398,28 @@ pub fn setgid(gid: Gid) -> Result<()> { Errno::result(res).map(drop) } -/// Set the user identity used for filesystem checks +/// Set the user identity used for filesystem checks. +/// On both success and failure, this call returns the previous filesystem user +/// ID of the caller. /// /// See also [setfsuid(2)](http://man7.org/linux/man-pages/man2/setfsuid.2.html) #[cfg(target_os = "linux")] #[inline] -pub fn setfsuid(uid: Uid) -> Result<()> { - let res = unsafe { libc::setfsuid(uid.into()) }; - - Errno::result(res).map(drop) +pub fn setfsuid(uid: Uid) -> Uid { + let prev_fsuid = unsafe { libc::setfsuid(uid.into()) }; + Uid::from_raw(prev_fsuid as uid_t) } -/// Set the group identity used for filesystem checks +/// Set the group identity used for filesystem checks. +/// On both success and failure, this call returns the previous filesystem group +/// ID of the caller. /// /// See also [setfsgid(2)](http://man7.org/linux/man-pages/man2/setfsgid.2.html) #[cfg(target_os = "linux")] #[inline] -pub fn setfsgid(gid: Gid) -> Result<()> { - let res = unsafe { libc::setfsgid(gid.into()) }; - - Errno::result(res).map(drop) +pub fn setfsgid(gid: Gid) -> Gid { + let prev_fsgid = unsafe { libc::setfsgid(gid.into()) }; + Gid::from_raw(prev_fsgid as gid_t) } /// Get the list of supplementary group IDs of the calling process.