Improve unreachable error messages

This commit is contained in:
Ben S
2016-01-27 19:39:19 +00:00
parent 78c4b410db
commit ce47457bba
+12 -12
View File
@@ -19,54 +19,54 @@ extern {
/// Sets current user for the running process, requires root priviledges.
pub fn set_current_uid(uid: uid_t) -> IOResult<()> {
match unsafe { setuid(uid) } {
0 => Ok(()),
0 => Ok(()),
-1 => Err(IOError::last_os_error()),
_ => unreachable!()
n => unreachable!("setuid returned {}", n)
}
}
/// Set current group for the running process, requires root priviledges.
pub fn set_current_gid(gid: gid_t) -> IOResult<()> {
match unsafe { setgid(gid) } {
0 => Ok(()),
0 => Ok(()),
-1 => Err(IOError::last_os_error()),
_ => unreachable!()
n => unreachable!("setgid returned {}", n)
}
}
/// Set effective user for the running process, requires root priviledges.
pub fn set_effective_uid(uid: uid_t) -> IOResult<()> {
match unsafe { seteuid(uid) } {
0 => Ok(()),
0 => Ok(()),
-1 => Err(IOError::last_os_error()),
_ => unreachable!()
n => unreachable!("seteuid returned {}", n)
}
}
/// Set effective user for the running process, requires root priviledges.
pub fn set_effective_gid(gid: gid_t) -> IOResult<()> {
match unsafe { setegid(gid) } {
0 => Ok(()),
0 => Ok(()),
-1 => Err(IOError::last_os_error()),
_ => unreachable!()
n => unreachable!("setegid returned {}", n)
}
}
/// Atomically set current and effective user for the running process, requires root priviledges.
pub fn set_both_uid(ruid: uid_t, euid: uid_t) -> IOResult<()> {
match unsafe { setreuid(ruid, euid) } {
0 => Ok(()),
0 => Ok(()),
-1 => Err(IOError::last_os_error()),
_ => unreachable!()
n => unreachable!("setreuid returned {}", n)
}
}
/// Atomically set current and effective group for the running process, requires root priviledges.
pub fn set_both_gid(rgid: gid_t, egid: gid_t) -> IOResult<()> {
match unsafe { setregid(rgid, egid) } {
0 => Ok(()),
0 => Ok(()),
-1 => Err(IOError::last_os_error()),
_ => unreachable!()
n => unreachable!("setregid returned {}", n)
}
}