Skip to content

Commit f5a0bcc

Browse files
committed
support setresgid in os module
1 parent b03b892 commit f5a0bcc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

vm/src/stdlib/os.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,23 @@ 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<(i32)> {
15281544
let ret = unsafe { libc::setregid(rgid, egid) };
15291545
if ret == 0 {
15301546
Ok(0)
@@ -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)