Subject: Re: FreeBSD hosted build problem: mtree and user_from_uid()
To: \"Valeriy E. Ushakov\" <uwe@ptc.spbu.ru>
From: Mark Valentine <mark@valentine.me.uk>
List: current-users
Date: 10/10/2003 01:14:47
> From: uwe@ptc.spbu.ru ("Valeriy E. Ushakov")
> Date: Wed 8 Oct, 2003
> Subject: Re: FreeBSD hosted build problem: mtree and user_from_uid()

> On Wed, Oct 08, 2003 at 12:01:32 +0000, Mark Valentine wrote:
> > I naively tried just editing config.h to #define HAVE_USER_FROM_UID
> > 0 (shortcut for just removing the test for that function from
> > configure.ac, I think), but then the build blows up due to a
> > conflicting declaration of user_from_uid() in the host's <stdlib.h>
> > (argh!).
> 
> We have an example of a workaround for this conflict in compat_pwd.h.

Right, I played with that and ended up with the patch below, but I don't
like it much.

I first tried to have pwcache.c use compat_pwd.h, but it blows up with
the struct passwd stuff; I also tried to use the same technique as in
pw_scan.c, but that didn't even look close to working.

How far off base am I with this?

In general I don't like having to edit sources to use compat_pwd.h.

It can get hairy, but in the past with similar problems I've had some success
with having the compat headers with the same name as the real ones (e.g. pwd.h)
and using gcc's #include_next to effect minimally changed compatibility
headers (the scheme fell back to some very ugly build time editing of full-path
#includes when not using gcc...). You do have to be careful to avoid having
the same directory in the include search path multiple times when using that
technique.

		Cheers,

		Mark.

Index: lib/libc/gen/pwcache.c
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/pwcache.c,v
retrieving revision 1.24
diff -u -r1.24 pwcache.c
--- lib/libc/gen/pwcache.c	2003/08/07 16:42:55	1.24
+++ lib/libc/gen/pwcache.c	2003/10/08 17:14:48
@@ -132,6 +132,11 @@
 #if !HAVE_PWCACHE_USERDB
 #include "pwcache.h"
 
+#if HAVE_USER_FROM_UID
+#define user_from_uid __nbcompat_system_user_from_uid
+#define group_from_gid __nbcompat_system_group_from_gid
+#endif
+
 /*
  * routines that control user, group, uid and gid caches (for the archive
  * member print routine).
@@ -274,7 +279,6 @@
 	return (0);
 }
 
-#if !HAVE_USER_FROM_UID
 /*
  * user_from_uid()
  *	caches the name (if any) for the uid. If noname clear, we always
@@ -414,7 +418,6 @@
 	}
 	return (ptr->name);
 }
-#endif /* HAVE_USER_FROM_UID */
 
 /*
  * uid_from_user()
Index: usr.sbin/mtree/create.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/mtree/create.c,v
retrieving revision 1.43
diff -u -r1.43 create.c
--- usr.sbin/mtree/create.c	2003/08/07 11:25:35	1.43
+++ usr.sbin/mtree/create.c	2003/10/08 17:15:29
@@ -29,6 +29,10 @@
  * SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
 #if 0
@@ -48,7 +52,11 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
+#ifdef HAVE_CONFIG_H
+#include "compat_pwd.h"
+#else
 #include <pwd.h>
+#endif
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
Index: usr.sbin/mtree/spec.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/mtree/spec.c,v
retrieving revision 1.51
diff -u -r1.51 spec.c
--- usr.sbin/mtree/spec.c	2003/09/19 06:15:55	1.51
+++ usr.sbin/mtree/spec.c	2003/10/08 17:15:30
@@ -65,6 +65,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
 #if 0
@@ -80,7 +84,11 @@
 #include <ctype.h>
 #include <errno.h>
 #include <grp.h>
+#ifdef HAVE_CONFIG_H
+#include "compat_pwd.h"
+#else
 #include <pwd.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

-- 
"Tigers will do ANYTHING for a tuna fish sandwich."
"We're kind of stupid that way."   *munch* *munch*
  -- <http://www.calvinandhobbes.com>