Skip to content

Commit 18853a8

Browse files
committed
unistd::getgrouplist: Add a note about returning an error
1 parent b589795 commit 18853a8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/unistd.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,14 @@ pub fn setgroups(groups: &[Gid]) -> Result<()> {
10141014
/// groups that `user` is a member of. The additional group `group` is also
10151015
/// added to the list.
10161016
///
1017+
/// *Note:* Although the `getgrouplist()` call does not return any specific
1018+
/// errors on any known platforms, this implementation will return a system
1019+
/// error of `EINVAL` if the number of groups to be fetched exceeds the
1020+
/// `NGROUPS_MAX` sysconf value. This mimics the behaviour of `getgroups()`
1021+
/// and `setgroups()`. Additionally, while some implementations will return a
1022+
/// partial list of groups when `NGROUPS_MAX` is exceeded, this implementation
1023+
/// will only ever return the complete list or else an error.
1024+
///
10171025
/// [Further reading](http://man7.org/linux/man-pages/man3/getgrouplist.3.html)
10181026
pub fn getgrouplist(user: &CString, group: Gid) -> Result<Vec<Gid>> {
10191027
let ngroups_max = match sysconf(SysconfVar::NGROUPS_MAX) {
@@ -1051,7 +1059,6 @@ pub fn getgrouplist(user: &CString, group: Gid) -> Result<Vec<Gid>> {
10511059
let cap = groups.capacity();
10521060
if cap >= ngroups_max as usize {
10531061
// We already have the largest capacity we can, give up
1054-
// FIXME: What error should be returned?
10551062
return Err(Error::invalid_argument())
10561063
}
10571064

0 commit comments

Comments
 (0)