Skip to content

Commit 5b9a4d8

Browse files
committed
unistd: Add notes about macOS complications with get/setgroups
1 parent f760287 commit 5b9a4d8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/unistd.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,12 @@ pub fn setgid(gid: Gid) -> Result<()> {
943943

944944
/// Get the list of supplementary group IDs of the calling process.
945945
///
946+
/// *Note:* On macOS, `getgroups()` behavior differs somewhat from other Unix
947+
/// platforms. It returns the current group access list for the user associated
948+
/// with the effective user id of the process; the group access list may change
949+
/// over the lifetime of the process, and it is not affected by calls to
950+
/// `setgroups()`.
951+
///
946952
/// [Further reading](http://pubs.opengroup.org/onlinepubs/009695399/functions/getgroups.html)
947953
pub fn getgroups() -> Result<Vec<Gid>> {
948954
// First get the number of groups so we can size our Vec
@@ -978,6 +984,9 @@ pub fn getgroups() -> Result<Vec<Gid>> {
978984

979985
/// Set the list of supplementary group IDs for the calling process.
980986
///
987+
/// *Note:* On macOS, `getgroups()` may not return the same group list set by
988+
/// calling `setgroups()`. Apple discourages the use of `setgroups()`.
989+
///
981990
/// [Further reading](http://man7.org/linux/man-pages/man2/getgroups.2.html)
982991
pub fn setgroups(groups: &[Gid]) -> Result<()> {
983992
cfg_if! {

test/test_unistd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ mod linux_android {
105105
}
106106

107107
#[test]
108+
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
108109
fn test_setgroups() {
109110
if !Uid::current().is_root() {
110111
// setgroups() requires root

0 commit comments

Comments
 (0)