Author Alexander.Belopolsky
Recipients Alexander.Belopolsky, l0nwlf, loewis, michael.foord, orsenthil, ronaldoussoren
Date 2010-02-23.13:18:27
SpamBayes Score 0.0
Marked as misclassified No
Message-id <d38f5331002230518w4f002736k449380997523ad12@mail.gmail.com>
In-reply-to <1266909655.38.0.892015151078.issue7900@psf.upfronthosting.co.za>
Content
On Tue, Feb 23, 2010 at 2:20 AM, Ronald Oussoren <report@bugs.python.org> wrote:
> ..
> Alexander:  What makes you think r63955 introduced the problem?

That revision introduced _DARWIN_C_SOURCE which, as I explained, has
two effects on get/setgroups:

"""
It turns out that defining _DARWIN_C_SOURCE not only allows
getgroups() output to exceed NGROUPS_MAX (as documented), but also
effectively disables setgroups() which is not documented.
"""

I further added:

"""
In order to have both working os.setgroups() and os.getgroups()
supporting more than NGROUPS_MAX results, it appears that the two
functions should be compiled in separate compilation units which is
probably too big of a price to pay for the functionality.
"""

I agree that this is a important distinction, but I seem to recall
discussion on python-dev or elsewhere on the tracker that concluded
that unexpected exceptions can be classified as crashes.  For most
users the difference between hard and soft crash is purely academic -
in either case their python program terminates due to a bug in python
and the "type" menu does not have separate entries for hard and soft
crashes.

> The Apple fix for getgroups in python2.6 is odd, it uses an undocumented API
> (getgrouplist_2).

I agree, Apple patch is not acceptable.  Not only it is undocumented,
but I suspect it is simply wrong because getgrouplist_2 is likely to
be a variant of getgrouplist that handles memory allocation and
returns group list from system's group database rather than from
per-process setting. (I have not verified that point, though.)

>
> If I read the manpage correctly there is a posixly correct way to implement os.getgroups:
>
> * call getgroups(MAX_GROUPS,...)

Note that MAX_GROUPS is 65536 on Linux and may be even higher on other
systems.  Allocating 256K on heap is wasteful and allocating the same
on the stack may even hard crash python.

> * if that fails: call getgroups(0,...), the result is groupcount

Please note the following comment I found in GNU coreutils source code:

/* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always
   fails.  On other systems, it returns the number of supplemental
   groups for the process.  This function handles that special case
   and lets the system-provided function handle all others.  However,
   it can fail with ENOMEM if memory is tight.  It is unspecified
   whether the effective group id is included in the list.  */

This is more or less what my original patch did, but it suffers from a
race condition.

I am attaching a patch that I wrote yesterday, but did not submit
because it does not fix setgroups.  I am attaching it now so that we
can compare our approaches.
Files
File name Uploaded
issue7900-1.diff Alexander.Belopolsky, 2010-02-23.13:18:26
History
Date User Action Args
2010-02-23 13:18:30Alexander.Belopolskysetrecipients: + Alexander.Belopolsky, loewis, ronaldoussoren, orsenthil, michael.foord, l0nwlf
2010-02-23 13:18:29Alexander.Belopolskylinkissue7900 messages
2010-02-23 13:18:27Alexander.Belopolskycreate