Bug 2577 - getpwuid_r fails on NetBSD
Summary: getpwuid_r fails on NetBSD
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: Lib/Xlib (show other bugs)
Version: unspecified
Hardware: x86 (IA32) NetBSD
: high normal
Assignee: Roland Mainz
QA Contact: Xorg Project Team
URL:
Whiteboard:
Keywords:
: 3293 3372 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-02-19 07:50 UTC by Michael Banck
Modified: 2009-02-17 06:12 UTC (History)
4 users (show)

See Also:
i915 platform:
i915 features:


Attachments
proposed patch by Robert Millan (25.40 KB, patch)
2005-02-19 07:51 UTC, Michael Banck
no flags Details | Splinter Review
proposed patch by Robert Millan (correct file this time) (5.36 KB, patch)
2005-02-19 07:54 UTC, Michael Banck
no flags Details | Splinter Review
Patch with unnecessary hunks removed (3.87 KB, patch)
2005-02-19 19:58 UTC, Michael Banck
no flags Details | Splinter Review
Patch to Xos_r.h to detect error properly and use correct version on Solaris (1.43 KB, patch)
2005-03-02 11:22 UTC, Alan Coopersmith
no flags Details | Splinter Review
patch for NetBSD.cf (597 bytes, patch)
2006-03-23 22:08 UTC, Harald van Dijk
no flags Details | Splinter Review
Similar patch for libX11 (709 bytes, patch)
2006-03-24 02:36 UTC, Harald van Dijk
no flags Details | Splinter Review

Description Michael Banck 2005-02-19 07:50:26 UTC
there is a failure when building xprint on GNU/Hurd on Debian unstable:

gcc -c -O2 -fno-strength-reduce -fno-strict-aliasing  -ansi -pedantic -Wall
-Wpointer-arith -Wstrict-prot
otypes                    -Wmissing-prototypes -Wmissing-declarations          
          -Wredundant-dec
ls -Wnested-externs -Wundef    -I../.. -I../../exports/include   -D__i386__
-D_POSIX_C_SOURCE=199309L    
                           -D_POSIX_SOURCE -D_XOPEN_SOURCE                     
         -D_BSD_SOURCE -D
_SVID_SOURCE  -DFUNCPROTO=15 -DNARROWPROTO -DXTHREADS  -D_REENTRANT
-DXUSE_MTSAFE_API    -DMALLOC_0_RETUR
NS_NULL     -fPIC XpJob.c
XpJob.c: In function `XpStartJob':
XpJob.c:108: error: too few arguments to function `getpwuid_r'
make[5]: *** [XpJob.o] Error 1

The attached patch by Robert Millan has been integrated into both the Debian
xfree86 package and Ubuntu's xorg package, and should fix this. He generated the
patch for GNU/k*BSD, so I guess that system would fail to build xprint currently
as well.

Not sure whether this patch would propagate to xorg from this bug report
automatically, or whether I should file a seperate bug there.


cheers,

Michael
Comment 1 Michael Banck 2005-02-19 07:51:39 UTC
Created attachment 1941 [details] [review]
proposed patch by Robert Millan
Comment 2 Michael Banck 2005-02-19 07:54:28 UTC
Created attachment 1942 [details] [review]
proposed patch by Robert Millan (correct file this time)
Comment 3 Michael Banck 2005-02-19 19:58:30 UTC
Created attachment 1944 [details] [review]
Patch with unnecessary hunks removed

Some parts of the original patch reference parts of the xorg source which is no
in xprint, so these were deleted
Comment 4 Roland Mainz 2005-03-02 08:27:51 UTC
(In reply to comment #3)
> Created an attachment (id=1944) [edit]
> Patch with unnecessary hunks removed
> 
> Some parts of the original patch reference parts of the xorg source which is no
> in xprint, so these were deleted

This kind of stripping isn't needed as the Xprint and X.org founation CVS trees
have been merged in X11R6.8.0 (actually Xprint was added in the X.org consortium
release X11R6.3 but various vendors kept their drivers in their own source trees
without sending them back to X.org (that changed with X11R6.8.0)).
Comment 5 Roland Mainz 2005-03-02 08:28:40 UTC
Comment on attachment 1944 [details] [review]
Patch with unnecessary hunks removed

Moving back to previous patch...
Comment 6 Roland Mainz 2005-03-02 08:29:48 UTC
Comment on attachment 1942 [details] [review]
proposed patch by Robert Millan (correct file this time)

Alan:
Can you check whether the patch is OK for you, please ?
Comment 7 Alan Coopersmith 2005-03-02 11:10:50 UTC
Comment on attachment 1942 [details] [review]
proposed patch by Robert Millan (correct file this time)

This patch is broken:
 1) "dumy" typo in Xt/Initialize.c
 2) It changes the call from the 4-arg version to the 5-arg version on
platforms which only use 4-args.

For instance, after applying, Solaris builds fail with:
"Initialize.c", line 307: prototype mismatch: 5 args passed, 4 expected
"Initialize.c", line 356: undefined symbol: dumy
"Initialize.c", line 356: prototype mismatch: 5 args passed, 4 expected
"Initialize.c", line 358: prototype mismatch: 5 args passed, 4 expected

It doesn't correct the other bug in the calls to the 5-arg version, which is
that they return an errno value on failure, not -1, so failure is incorrectly
detected.

The correct fix would be to adjust the defines for platforms that use the 5-arg
variant to use the support in Xos_r.h that already exists for it, without
having to change any callers - it should fall through to the
_POSIX_THREAD_SAFE_FUNCTIONS  set of code at line 367 of Xos_r.h that handles
the 5-arg variant and includes the needed pointer in the  _Xgetpwparams so the
callers don't have to be modified to define a dummy pointer themselves.
Comment 8 Alan Coopersmith 2005-03-02 11:22:06 UTC
Created attachment 2007 [details] [review]
Patch to Xos_r.h to detect error properly and use correct version on Solaris

This patch (which I'm committing to head now) fixes the afore-mentioned bug in
checking the return values from the POSIX-conformant version, and fixes the
Solaris #ifdefs.   It doesn't solve the main problem of this bug, the #ifdefs
choosing the wrong version for these platforms, but I don't know what the
correct #defines to check for those platforms is, so leave that to someone who
does.
Comment 9 Roland Mainz 2005-03-02 22:30:16 UTC
Michael/Robert:
Can you make a new patch for GNU/Hurd to match Alan's review comments, please ?
Comment 10 Michael Banck 2005-03-03 16:44:08 UTC
We will try to come up with a patch. However, I had looked at Xos_r.h for quite
a while before I found Robert's patch and could not really figure out how/where
platforms are supposed to define their version of getpwuid_r.

Also note that GNU/Linux and GNU/Hurd (as are GNU/k*BSD) both are variants of
the GNU system and thus are both based on glibc. So it would perhaps be better
to just define this properly for glibc and make Linux and Hurd define glibc.
Comment 11 Alan Coopersmith 2005-03-03 17:09:19 UTC
If glibc is providing the POSIX thread interfaces, it should
#define _POSIX_THREAD_SAFE_FUNCTIONS, in which case Xos_r.h 
should choose the correct 5-arg variant.    To get those variants
used when that's not defined, add the appropriate check for your
platform to this section of the checks:

#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(__APPLE__)

so for instance if the 5-arg versions were to be used any time GNU_HURD_HERE was
defined, you'ld change it to:

#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(__APPLE__) &&
!defined(GNU_HURD_HERE)

and it would fall into the #else case about 30 lines lower that uses the 
POSIX 5-arg calls.
Comment 12 Alan Coopersmith 2005-05-23 08:56:34 UTC
*** Bug 3372 has been marked as a duplicate of this bug. ***
Comment 13 Alan Coopersmith 2005-05-23 08:58:37 UTC
Changing from xprint to xorg so people find it.
Comment 14 Jeremy C. Reed 2005-11-22 14:30:16 UTC
Similar problem on NetBSD/i386 3.0_BETA also with libX11 and libXt.

Initialize.c:357: error: too few arguments to function `getpwnam_r'
Initialize.c:359: error: too few arguments to function `getpwuid_r'

My workaround:

-DXNO_MTSAFE_PWDAPI -D_REENTRANT
Comment 15 Alan Coopersmith 2005-11-22 15:44:23 UTC
So what define does this code need to check for on NetBSD to find out which
version of the functions to use?   Is it simply that all versions of NetBSD
use the 5-arg variants or was it changed at some point or controlled by some
other #ifdef?
Comment 16 Jeremy C. Reed 2005-11-22 17:06:57 UTC
Sorry I do not know what define is needed.

Looking closer, I see these reentrant functions were added to NetBSD in Oct.
2004 and they will be in the NetBSD 3 to be released real soon (maybe before
X.org is released).

This NetBSD pwd.h has:

#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \        
                    
    defined(_REENTRANT) || defined(_NETBSD_SOURCE)                             
                    
int              getpwnam_r(const char *, struct passwd *, char *, size_t,     
                    
                                struct passwd **);                             
                    
int              getpwuid_r(uid_t, struct passwd *, char *, size_t,            
                    
                                struct passwd **);                             
                    
#endif
Comment 17 Harald van Dijk 2006-03-23 22:08:44 UTC
Created attachment 5032 [details] [review]
patch for NetBSD.cf

Hi, 6.9.0 works on NetBSD 3.0 for me with this. <threadlib.h> was removed
December 2004 according to the CVS log, about the same time the reentrant
functions were added according to the above message, so I simply used that
check. It may not be perfect, but hopefully it's good enough. I don't know
enough to give you a better check, sorry.
Comment 18 Harald van Dijk 2006-03-24 02:36:25 UTC
Created attachment 5033 [details] [review]
Similar patch for libX11

And for libX11's configure script, a similar patch works.
Comment 19 Michael Banck 2006-04-28 21:53:30 UTC
(In reply to comment #11)
> If glibc is providing the POSIX thread interfaces, it should
> #define _POSIX_THREAD_SAFE_FUNCTIONS, in which case Xos_r.h 
> should choose the correct 5-arg variant.

Indeed, it turned out that <bits/posix_opt.h> got updated recently (now
#defining _POSIX_THREAD_SAFE_FUNCTIONS) for GNU/Hurd (it is in glibc-2.4), my
glibc-2.3.6 based system does not have this yet.

As far as libX11 is concerned, it builds fine on GNU/Hurd with the updated
system header now, so this is NOTABUG as far as we are concerned (maybe retitle
to NetBSD).


thanks,

Michael
Comment 20 Daniel Stone 2007-02-27 01:25:26 UTC
Sorry about the phenomenal bug spam, guys.  Adding xorg-team@ to the QA contact so bugs don't get lost in future.
Comment 21 Alan Coopersmith 2008-08-04 19:23:39 UTC
*** Bug 3293 has been marked as a duplicate of this bug. ***
Comment 22 Julien Cristau 2009-02-17 06:12:24 UTC
looks like this was fixed a while ago

commit 129bbb9f9114a571556fa3a24f15ba58a5cdb2de
Author: Jeremy C. Reed <reed@glacier.reedmedia.net>
Date:   Thu Dec 14 14:21:19 2006 -0600

    For NetBSD, define the XTHREADLIB and XTHREAD_CFLAGS.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.