svn commit: r209542 - head/lib/libc/sys

Bruce Evans brde at
Sun Jun 27 16:31:51 UTC 2010

On Sat, 26 Jun 2010, Garrett Cooper wrote:

Please fix your mail program to not mangle the message with \xa0's.

> On Sat, Jun 26, 2010 at 2:44 PM, Pawel Jakub Dawidek <pjd at> wrote:
>> Log:
>>  Just like in case of setgroups(2), for getgroups(2) also advice including
>>  sys/param.h instead of sys/types.h so we get NGROUPS_MAX and NGROUPS
>>  definitions.

This bug should have been fixed in getgroups.2, not duplicated.  It was
fixed in getgroups.2 in 1998, but not in setgroups, presumably because
POSIX only specified getgroups back then:

% RCS file: /home/ncvs/src/lib/libc/sys/getgroups.2,v
% Working file: getgroups.2
% head: 1.12
% ----------------------------
% revision 1.3
% date: 1998/01/11 22:01:20;  author: alex;  state: Exp;  lines: +9 -1
% Replace sys/param.h with sys/types.h as per POSIX.
% Document the special case of gidsetlen == 0.
% Partially obtained from: OpenBSD
% ----------------------------

This is a bug because:
- neither NGROUPS_MAX nor NGROUPS is needed to use get/setgroups().  These
   functions take an int arg which may be unrelated to the maximum number
   of groups
- all uses of NGROUPS_MAX and NGROUPS are bugs, since they are fixed values
   so using them breaks binary compatibility
- FreeBSD was fixed relatively recently to never (?) use NGROUPS_MAX or
   NGROUPS.  The fixes include removing the reference to NGROUPS max
   in getgroups.2 and the reference to NGROUPS in setgroups.2.  Now
   {NGROUPS_MAX}+1 is used consistently.  This cannot be found in
   <sys/param.h>.  (It's documentation seems to be unfindable in any,
   man page but that is another bug.  POSIX limits should be described
   somewhere like intro.2 and intro.2 should not be cross referenced to.)

>    Hmmm... looks like our copy of getgroups(2) is not POSIX compliant
> then :/ :

It only used to be, after the 1998 fix.  POSIX didn't have setgroups() in
2001 either.

> . Why not just use sysconf like the POSIX page suggests (which is
> portable)?

FreeBSD's man page says this too (implicitly via the {} markup).  POSIX
has an explicit example using sysconf().  I prefer not to have such
examples in individual man pages.  They are difficult to give in enough
detail to work in general.  POSIX has very wrong examples for use of
{LINE_MAX}.  Its example for {NGROUPS_MAX} for getgroups() is little
better -- it is missing an include of <stdlib.h> to declare malloc(),
and has no error handling.  I would prefer a central example that is
missing these bugs but describes the shortcuts of having them.


More information about the svn-src-head mailing list