Skip to content

Commit

Permalink
fix return value for setfsuid and setfsgid
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Conte committed Dec 18, 2019
1 parent 0068ad3 commit 17890ea
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/unistd.rs
Expand Up @@ -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.
Expand Down

0 comments on commit 17890ea

Please sign in to comment.