diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 05b0f985c..0c2ffabf8 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -1524,10 +1524,26 @@ fn os_getresgid(vm: &VirtualMachine) -> PyResult<(u32, u32, u32)> { target_os = "linux", target_os = "openbsd" ))] -fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult { +fn os_setresgid(rgid: u32, egid: u32, sgid: u32, vm: &VirtualMachine) -> PyResult<()> { + unistd::setresgid( + Gid::from_raw(rgid), + Gid::from_raw(egid), + Gid::from_raw(sgid), + ) + .map_err(|err| convert_nix_error(vm, err)) +} + +// cfg from nix +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "linux", + target_os = "openbsd" +))] +fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<()> { let ret = unsafe { libc::setregid(rgid, egid) }; if ret == 0 { - Ok(0) + Ok(()) } else { Err(errno_err(vm)) } @@ -1798,6 +1814,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) { "setresuid" => ctx.new_function(os_setresuid), "getresuid" => ctx.new_function(os_getresuid), "getresgid" => ctx.new_function(os_getresgid), + "setresgid" => ctx.new_function(os_setresgid), "setregid" => ctx.new_function(os_setregid), "initgroups" => ctx.new_function(os_initgroups), "setgroups" => ctx.new_function(os_setgroups),