Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Oct 2005 11:22:48 -0700 (PDT)
From:      Doug Ambrisko <ambrisko@ambrisko.com>
To:        Kris Kennaway <kris@obsecurity.org>
Cc:        freebsd-emulation@freebsd.org
Subject:   Re: cross platform building under emulation
Message-ID:  <200510181822.j9IIMmHk057648@ambrisko.com>
In-Reply-To: <20051018181351.GB89074@xor.obsecurity.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Kris Kennaway writes:
| On Fri, Oct 14, 2005 at 07:27:00PM -0700, Doug Ambrisko wrote:
| > Dan Langille writes:
| > | Daris has got me thinking about unpacking 4.9-release/bin into a 
| > | directory, and then doing a chroot.
| > 
| > That sort-of works.  I've done some setups for companies and get
| > iteratively better solutions.  I copy over some host bins & libs
| > into special directories so mount, ps etc can be run from inside.
| > I also have mods to libc so that uname & getosreldate so it can
| > be set via env. variables so pkg_add, autoconf etc picks up the
| > right stuff.  Now this is a little trickier for old version of
| > libc that I haven't modified locally yet so I build a stub lib.
| > of these in the chroot then load this then LD_PRELOAD.  If you don't
| > then some things get messed up.
| > 
| > This lets me build on a FreeBSD 6.X/amd64 host for FreeBSD 4.X/386, 
| > FreeBSD amd64 etc.  I've also at times loaded in the Linux tools and
| > made that work so I could build Linux bins in chroots.
| > 
| > I hope to commit my changes to getosreldate(3) and uname(3).
| > This mirrors the env. variables in /usr/bin/uname.
| 
| I'd find this very useful too (and will start using your patch),
| thanks!

Please don't use that.  Instead this one works better.  The prior
one caused getty and xdm to core dump :-(

Index: lib/libc/gen/__xuname.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/__xuname.c,v
retrieving revision 1.9
diff -u -p -r1.9 __xuname.c
--- lib/libc/gen/__xuname.c	1 Feb 2002 00:57:29 -0000	1.9
+++ lib/libc/gen/__xuname.c	18 Oct 2005 18:18:29 -0000
@@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysctl.h>
 #include <sys/utsname.h>
 #include <errno.h>
+#include <stdlib.h>
+#include <string.h>
 
 int
 __xuname(int namesize, void *namebuf)
@@ -71,6 +73,8 @@ __xuname(int namesize, void *namebuf)
 			rval = -1;
 	}
 	name->sysname[sizeof(name->sysname) - 1] = '\0';
+	if ((p = getenv("UNAME_s")))
+		strncpy(name->sysname, p, sizeof(name->sysname));
 
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_HOSTNAME;
@@ -95,6 +99,8 @@ __xuname(int namesize, void *namebuf)
 			rval = -1;
 	}
 	name->release[sizeof(name->release) - 1] = '\0';
+	if ((p = getenv("UNAME_r")))
+		strncpy(name->release, p, sizeof(name->release));
 
 	/* The version may have newlines in it, turn them into spaces. */
 	mib[0] = CTL_KERN;
@@ -116,6 +122,8 @@ __xuname(int namesize, void *namebuf)
 				*p = '\0';
 		}
 	}
+	if ((p = getenv("UNAME_v")))
+		strncpy(name->version, p, sizeof(name->version));
 
 	mib[0] = CTL_HW;
 	mib[1] = HW_MACHINE;
@@ -128,5 +136,7 @@ __xuname(int namesize, void *namebuf)
 			rval = -1;
 	}
 	name->machine[sizeof(name->machine) - 1] = '\0';
+	if ((p = getenv("UNAME_m")))
+		strncpy(name->machine, p, sizeof(name->machine));
 	return (rval);
 }
Index: lib/libc/gen/getosreldate.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/getosreldate.c,v
retrieving revision 1.7
diff -u -p -r1.7 getosreldate.c
--- lib/libc/gen/getosreldate.c	12 Sep 2005 19:52:41 -0000	1.7
+++ lib/libc/gen/getosreldate.c	18 Oct 2005 18:18:29 -0000
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
+#include <stdlib.h>
 
 #include <osreldate.h>
 
@@ -49,10 +50,14 @@ getosreldate(void)
 	size_t size;
 	int value;
 
+	char *temp;
+
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_OSRELDATE;
 	size = sizeof value;
 	if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)
 		return (-1);
+	if ((temp = getenv("OSVERSION")))
+		value = atoi(temp);
 	return (value);
 }

Please let me know how this one goes.

If you are interested I could give you stuff to build a shared lib
wedge of this to retrofit it into older shared lib binaries.

Doug A.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200510181822.j9IIMmHk057648>