Skip to content

Commit 7a89a4b

Browse files
authored
Merge pull request RustPython#1961 from mrmiywj/support_setresgid_in_os_module
Support setresgid in os module
2 parents f284b4c + 6a1d7a8 commit 7a89a4b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

vm/src/stdlib/os.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,10 +1524,26 @@ fn os_getresgid(vm: &VirtualMachine) -> PyResult<(u32, u32, u32)> {
15241524
target_os = "linux",
15251525
target_os = "openbsd"
15261526
))]
1527-
fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<i32> {
1527+
fn os_setresgid(rgid: u32, egid: u32, sgid: u32, vm: &VirtualMachine) -> PyResult<()> {
1528+
unistd::setresgid(
1529+
Gid::from_raw(rgid),
1530+
Gid::from_raw(egid),
1531+
Gid::from_raw(sgid),
1532+
)
1533+
.map_err(|err| convert_nix_error(vm, err))
1534+
}
1535+
1536+
// cfg from nix
1537+
#[cfg(any(
1538+
target_os = "android",
1539+
target_os = "freebsd",
1540+
target_os = "linux",
1541+
target_os = "openbsd"
1542+
))]
1543+
fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<()> {
15281544
let ret = unsafe { libc::setregid(rgid, egid) };
15291545
if ret == 0 {
1530-
Ok(0)
1546+
Ok(())
15311547
} else {
15321548
Err(errno_err(vm))
15331549
}
@@ -1798,6 +1814,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
17981814
"setresuid" => ctx.new_function(os_setresuid),
17991815
"getresuid" => ctx.new_function(os_getresuid),
18001816
"getresgid" => ctx.new_function(os_getresgid),
1817+
"setresgid" => ctx.new_function(os_setresgid),
18011818
"setregid" => ctx.new_function(os_setregid),
18021819
"initgroups" => ctx.new_function(os_initgroups),
18031820
"setgroups" => ctx.new_function(os_setgroups),

0 commit comments

Comments
 (0)