[PATCH] linedit, deluser: use POSIX getpwent instead of getpwent_r

Denys Vlasenko vda.linux at googlemail.com
Sat Feb 7 20:22:57 UTC 2015


You convinced me. I just committed a change which got rid of getpwent_r.

Please try current git and let me know if I messed up.

On Sat, Feb 7, 2015 at 6:54 PM, Rich Felker <dalias at libc.org> wrote:
> On Sat, Feb 07, 2015 at 09:49:19AM -0800, Isaac Dunham wrote:
>> On Thu, Feb 05, 2015 at 03:52:24PM -0500, Rich Felker wrote:
>> > On Thu, Feb 05, 2015 at 09:42:08PM +0100, Denys Vlasenko wrote:
>> > > struct passwd *getpwent()
>> > > {
>> > >         static char *line;
>> > >         static struct passwd pw;
>> > >         size_t size=0;
>> > >         if (!f) f = fopen("/etc/passwd", "rbe");
>> > >         if (!f) return 0;
>> > >         return __getpwent_a(f, &pw, &line, &size);
>> > > }
>> > >
>> > > I would prefer that even "struct passwd" is malloced...
>> >
>> > I don't think it would make much practical difference. It could be
>> > changed though.
>> >
>> > > But more importantly, bbox can't optimize only for musl.
>> > > Other libc'es  may have static line buffers there.
>> > >
>> > > And musl will eventually be forced to implement getpwent_r()
>> > > if it wants to be usable for more packages... so...
>> >
>> > getpwent_r makes no sense; the _r functions are for thread-safe
>> > versions of their corresponding legacy functions, but getpwent_r has
>> > inherent global state -- the iterator. Whoever made it just wasn't
>> > thinking. To make a correct interface like this the caller would need
>> > to have an iterator object to pass to the function, but I can't see
>> > much merit in inventing a new interface for this.
>>
>> Besides having hidden global state, the man page notes:
>>  Other systems  use  the prototype
>>   struct passwd *getpwent_r(struct passwd *pwd, char *buf, int buflen);
>>  or, better,
>>   int getpwent_r(struct passwd *pwd, char *buf, int buflen, FILE **pw_fp);
>>
>> In other words, according to the manpage, getpwent_r() is decidedly
>> unportable.
>>
>> Per my investigations, Dragonfly/Net/FreeBSD seem to use the same
>> prototype as glibc; apparently Solaris uses the first alternate prototype;
>> and the last mentioned seems to be a reference to Tru64, which
>> uses pw_fp to keep track of its position instead of an iterator.
>>
>> OpenBSD and MirBSD do not implement getpwent_r, as far as I can tell.
>
> It should be noted here that multiple conflicting historical
> definitions of a nonstandard interface are one of the big exclusion
> criteria musl goes by.
>
> Rich
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list