summaryrefslogtreecommitdiff
path: root/pkgtools/libkver/files
diff options
context:
space:
mode:
Diffstat (limited to 'pkgtools/libkver/files')
-rw-r--r--pkgtools/libkver/files/Makefile5
-rw-r--r--pkgtools/libkver/files/Makefile.inc32
-rw-r--r--pkgtools/libkver/files/lib/Makefile5
-rw-r--r--pkgtools/libkver/files/lib/kver.347
-rw-r--r--pkgtools/libkver/files/lib/kver.c192
-rw-r--r--pkgtools/libkver/files/lib/shlib_version4
-rw-r--r--pkgtools/libkver/files/sysctl/Makefile4
7 files changed, 196 insertions, 93 deletions
diff --git a/pkgtools/libkver/files/Makefile b/pkgtools/libkver/files/Makefile
index 5347f5aab84..6fd0ea8fed4 100644
--- a/pkgtools/libkver/files/Makefile
+++ b/pkgtools/libkver/files/Makefile
@@ -1,11 +1,12 @@
-# $NetBSD: Makefile,v 1.2 2003/07/20 15:37:47 seb Exp $
+# $NetBSD: Makefile,v 1.3 2003/12/13 17:45:59 seb Exp $
SUBDIR= lib
+.ifndef(LDD_SYSCTL)
LDD_SYSCTL!= ldd /sbin/sysctl 2>&1
+.endif
.if empty(LDD_SYSCTL:M*libc*)
SUBDIR+= sysctl
.endif
.include <bsd.subdir.mk>
-.include "${.CURDIR}/Makefile.inc"
diff --git a/pkgtools/libkver/files/Makefile.inc b/pkgtools/libkver/files/Makefile.inc
index 825480fb8be..06583e5125e 100644
--- a/pkgtools/libkver/files/Makefile.inc
+++ b/pkgtools/libkver/files/Makefile.inc
@@ -1,27 +1,11 @@
-# $NetBSD: Makefile.inc,v 1.3 2003/10/27 20:31:42 seb Exp $
+# $NetBSD: Makefile.inc,v 1.4 2003/12/13 17:45:59 seb Exp $
-.include <bsd.own.mk>
-
-SUPPORTED_KVER_OSRELEASES+= 1.5
-SUPPORTED_KVER_OSRELEASES+= 1.5.1
-SUPPORTED_KVER_OSRELEASES+= 1.5.2
-SUPPORTED_KVER_OSRELEASES+= 1.5.3
-SUPPORTED_KVER_OSRELEASES+= 1.6
-SUPPORTED_KVER_OSRELEASES+= 1.6.1
-SUPPORTED_KVER_OSRELEASES+= 1.6.2
-KVER_OSREVISION.1.5= 105000000
-KVER_OSREVISION.1.5.1= 105000100
-KVER_OSREVISION.1.5.2= 105000200
-KVER_OSREVISION.1.5.3= 105000300
-KVER_OSREVISION.1.6= 106000000
-KVER_OSREVISION.1.6.1= 106000100
-KVER_OSREVISION.1.6.2= 106000200
-
-.if defined(KVER_OSRELEASE) && !empty(SUPPORTED_KVER_OSRELEASES:M${KVER_OSRELEASE})
-CFLAGS+= -D_KVER_OSREVISION=${KVER_OSREVISION.${KVER_OSRELEASE}}
+.if defined(PREFIX)
+# build from pkgsrc
+LIBDIR= ${PREFIX}/lib
+BINDIR= ${PREFIX}/sbin
+MANDIR= ${PREFIX}/man
.else
-.BEGIN:
- @echo "You must define KVER_OSRELEASE to be one of:"
- @echo "${SUPPORTED_KVER_OSRELEASES}"
- @false
+# build outside pkgsrc
+BINDIR= /sbin
.endif
diff --git a/pkgtools/libkver/files/lib/Makefile b/pkgtools/libkver/files/lib/Makefile
index c76f2a4fcc7..7be2ede610f 100644
--- a/pkgtools/libkver/files/lib/Makefile
+++ b/pkgtools/libkver/files/lib/Makefile
@@ -1,9 +1,10 @@
-# $NetBSD: Makefile,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $
+# $NetBSD: Makefile,v 1.2 2003/12/13 17:45:59 seb Exp $
NOPROFILE= # defined
NOLINT= # defined
-USE_SHLIBDIR= yes
+MKPICINSTALL= no
LIB= kver
+MAN= kver.3
SRCS= kver.c
.include <bsd.lib.mk>
diff --git a/pkgtools/libkver/files/lib/kver.3 b/pkgtools/libkver/files/lib/kver.3
new file mode 100644
index 00000000000..0404dc8df97
--- /dev/null
+++ b/pkgtools/libkver/files/lib/kver.3
@@ -0,0 +1,47 @@
+.\" $NetBSD: kver.3,v 1.1 2003/12/13 17:45:59 seb Exp $
+.\"
+.Dd December 13, 2003
+.Os
+.Dt KVER 3
+.Sh NAME
+.Nm kver
+.Nd override system version library
+.Sh SYNOPSIS
+LD_PRELOAD=.../libkver.so uname -a
+.Sh DESCRIPTION
+The
+.Nm
+library provides implementations of
+.Xr sysctl 3 and
+.Xr uname 3 that
+shadow the real implementation and could be configured to override the
+information identifying the current system.
+The library is usually loaded by the run-time link-editor via the
+LD_PRELOAD hook.
+.Pp
+This is useful for -among other things- building packages in a sandboxe,
+chrooted environment for a different
+.Nx
+release then the system hosting the sandbox.
+.Pp
+The library must be configured for reporting a specific
+.Nx
+release or else it emits a warning message on the standard error output.
+The value of the environment variable
+.Ev LIBKVER_OSRELEASE
+or the ``name'' of the file referenced by the symbolic link named
+.Pa /libkver_osrelease
+are checked in that order for the
+.Nx
+release number the library should reports information for.
+.Sh EXAMPLES
+.Dl env LD_PRELOAD=/lib/libkver.so LIBKVER_OSRELEASE=1.5 uname -r
+.Pp
+.Dl ln -s 1.6.2 /libkver_osrelease
+.Dl env LD_PRELOAD=/lib/libkver.so uname -r
+.Sh SEE ALSO
+.Xr ld.so 1 ,
+.Xr sysctl 3 ,
+.Xr uname 3
+.Sh AUTHORS
+.An Stoned Elipot Aq seb@netbsd.org
diff --git a/pkgtools/libkver/files/lib/kver.c b/pkgtools/libkver/files/lib/kver.c
index 7883b8a1b5c..9e16d8e2fda 100644
--- a/pkgtools/libkver/files/lib/kver.c
+++ b/pkgtools/libkver/files/lib/kver.c
@@ -1,4 +1,4 @@
-/* $NetBSD: kver.c,v 1.3 2003/10/27 20:31:42 seb Exp $ */
+/* $NetBSD: kver.c,v 1.4 2003/12/13 17:45:59 seb Exp $ */
#include <sys/types.h>
#include <sys/param.h>
@@ -7,40 +7,36 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
+#include <err.h>
+#include <stdlib.h>
+#include <ctype.h>
-#define KVER_VERSION_FMT "NetBSD %.6s (GENERIC) #0: %.40s root@localhost:/sys/arch/%.20s/compile/GENERIC"
-
-/* _KVER_DATE is not really the real release date but the
- date of src/sys/sys/param.h's revision tagged for the release */
-
-#if _KVER_OSREVISION == 105000000
-# define _KVER_OSRELEASE "1.5"
-# define _KVER_DATE "Wed Dec 6 00:00:00 UTC 2000"
-#elif _KVER_OSREVISION == 105000100
-# define _KVER_OSRELEASE "1.5.1"
-# define _KVER_DATE "Wed Jul 11 00:00:00 UTC 2001"
-#elif _KVER_OSREVISION == 105000200
-# define _KVER_OSRELEASE "1.5.2"
-# define _KVER_DATE "Thu Sep 13 00:00:00 UTC 2001"
-#elif _KVER_OSREVISION == 105000300
-# define _KVER_OSRELEASE "1.5.3"
-# define _KVER_DATE "Mon Jul 22 00:00:00 UTC 2002"
-#elif _KVER_OSREVISION == 106000000
-# define _KVER_OSRELEASE "1.6"
-# define _KVER_DATE "Sat Sep 14 00:00:00 UTC 2002"
-#elif _KVER_OSREVISION == 106000100
-# define _KVER_OSRELEASE "1.6.1";
-# define _KVER_DATE "Mon Apr 21 00:00:00 UTC 2003"
-#elif _KVER_OSREVISION == 106000200
-# define _KVER_OSRELEASE "1.6.2";
-# define _KVER_DATE "Tue Jan 19 00:00:00 UTC 2038"
-#else
-#error You must define _KVER_OSREVISION
+#define KVER_VERSION_FMT "NetBSD %s (LIBKVER) #0: Tue Jan 19 00:00:00 UTC 2038 root@localhost:/sys/arch/%s/compile/LIBKVER"
+
+#define KVER_NOT_INITIALIZED_OSRELEASE -2
+#define KVER_INVALID_OSRELEASE -1
+
+#ifndef PATH_LIBKVER_OSRELEASE
+#define PATH_LIBKVER_OSRELEASE "/libkver_osrelease"
+#endif
+#ifndef VAR_LIBKVER_OSRELEASE
+#define VAR_LIBKVER_OSRELEASE "LIBKVER_OSRELEASE"
#endif
-static char *kver_osrelease = _KVER_OSRELEASE;
-static char *kver_date = _KVER_DATE;
-static int kver_osrevision = _KVER_OSREVISION;
+static struct kver {
+ char osrelease[_SYS_NMLN];
+ int osrevision;
+ char version[_SYS_NMLN];
+} kver = {
+ "", KVER_NOT_INITIALIZED_OSRELEASE, ""
+};
+
+static struct utsname real_utsname;
+
+#define KVER_NOT_INITIALIZED \
+ (kver.osrevision == KVER_NOT_INITIALIZED_OSRELEASE)
+
+#define KVER_BADLY_INITIALIZED (kver.osrevision == KVER_INVALID_OSRELEASE)
#define SYSCTL_STRING(oldp, oldlenp, str) \
if (oldlenp) { \
@@ -57,22 +53,99 @@ static int kver_osrevision = _KVER_OSREVISION;
} \
}
-/* 6 chars for osrelease */
-/* 40 chars for the date string */
-/* 20 chars for utsname.machine */
-#define KVER_VERSION_LEN (sizeof(KVER_VERSION_FMT) + 6 + 40 + 20 + 1)
-static char kver_version[KVER_VERSION_LEN] = "";
-static struct utsname real_utsname;
+static int
+str2osrevision(char *s)
+{
+ char c;
+ int n, r = 0;
+
+ if (s == NULL || *s == 0)
+ return KVER_INVALID_OSRELEASE;
+
+ if (!isdigit(*s))
+ return KVER_INVALID_OSRELEASE;
+
+ /* first digit: major */
+ for (n = 0; isdigit(*s); s++) {
+ n = (n * 10) + (*s - '0');
+ }
+ if (*s == 0 || *s != '.')
+ return KVER_INVALID_OSRELEASE;
+ r += (n * 100000000);
+
+ /* second digit: minor */
+ for (s++, n = 0; isdigit(*s); s++) {
+ n = (n * 10) + (*s - '0');
+ }
+ r += (n * 1000000);
+
+ /* nothing more, return */
+ if (*s == 0)
+ return r;
+
+ /* optional third digit: patchlevel */
+ if (*s == '.') {
+ for (s++, n = 0; isdigit(*s); s++) {
+ n = (n * 10) + (*s - '0');
+ }
+ r += (n * 100);
+ if (*s != 0)
+ return KVER_INVALID_OSRELEASE;
+ return r;
+ }
+ /* or optional letters: release */
+ n = 0;
+ c = 'Z';
+ while (*s >= 'A' && *s <= 'Z') {
+ if (c != 'Z' && *s != 0)
+ break;
+ c = *s;
+ n += *s++ - '@';
+ }
+ if (n > 99)
+ return KVER_INVALID_OSRELEASE;
+ if (*s == 0)
+ return r + (n * 10000);
+
+ /* return on error if we end up here */
+ return KVER_INVALID_OSRELEASE;
+}
static void
-kver_init(void)
+kver_initialize(void)
{
- if (_uname(&real_utsname) != 0)
+ char *v;
+ int i;
+ kver.osrevision = KVER_INVALID_OSRELEASE; /* init done */
+ v = getenv(VAR_LIBKVER_OSRELEASE);
+ if (v == NULL) {
+ char b[MAXPATHLEN + 1];
+ i = readlink(PATH_LIBKVER_OSRELEASE, b, sizeof b - 1);
+ if (i <= 0) {
+ v = NULL;
+ } else {
+ b[i] = '\0';
+ v = b;
+ }
+ }
+ if (v == NULL) {
+ warnx("libkver: not configured");
+ return;
+ }
+ if (_uname(&real_utsname) != 0) {
+ warn("libkver: uname");
return;
- snprintf(kver_version, KVER_VERSION_LEN, KVER_VERSION_FMT,
- kver_osrelease,
- kver_date,
- real_utsname.machine);
+ }
+ kver.osrevision = str2osrevision(v);
+ if (kver.osrevision == KVER_INVALID_OSRELEASE) {
+ warnx("libkver: invalid version: %s", v);
+ return;
+ }
+ (void) strncpy(kver.osrelease, v, _SYS_NMLN);
+ kver.osrelease[_SYS_NMLN - 1] = '\0';
+ (void) snprintf(kver.version, _SYS_NMLN, KVER_VERSION_FMT,
+ kver.osrelease, real_utsname.machine);
+ return;
}
int
@@ -88,19 +161,18 @@ sysctl(int *name, u_int namelen, void *oldp, size_t * oldlenp, const void *newp,
errno = EINVAL;
return (-1);
}
+ if (KVER_NOT_INITIALIZED)
+ kver_initialize();
- if (*kver_version == '\0') {
- kver_init();
- if (*kver_version == '\0')
- return(-1);
- }
+ if (KVER_BADLY_INITIALIZED)
+ return -1;
if (name[0] == CTL_KERN) {
size_t len;
int r = 0;
switch (name[1]) {
case KERN_OSRELEASE:
- SYSCTL_STRING(oldp, oldlenp, kver_osrelease);
+ SYSCTL_STRING(oldp, oldlenp, kver.osrelease);
return (r);
case KERN_OSREV:
if (oldlenp) {
@@ -110,31 +182,31 @@ sysctl(int *name, u_int namelen, void *oldp, size_t * oldlenp, const void *newp,
if (*oldlenp < sizeof(int))
return (ENOMEM);
*oldlenp = sizeof(int);
- *((int *) oldp) = kver_osrevision;
+ *((int *) oldp) = kver.osrevision;
}
}
return (r);
case KERN_VERSION:
- SYSCTL_STRING(oldp, oldlenp, kver_version);
+ SYSCTL_STRING(oldp, oldlenp, kver.version);
return (r);
}
}
real: return (_sysctl(name, namelen, oldp, oldlenp, newp, newlen));
}
-
int
uname(struct utsname * n)
{
- if (*kver_version == '\0') {
- kver_init();
- if (*kver_version == '\0')
- return(-1);
- }
+ if (KVER_NOT_INITIALIZED)
+ kver_initialize();
+
+ if (KVER_BADLY_INITIALIZED)
+ return -1;
+
(void) strncpy(n->sysname, real_utsname.sysname, _SYS_NMLN);
(void) strncpy(n->nodename, real_utsname.nodename, _SYS_NMLN);
- (void) strncpy(n->release, kver_osrelease, _SYS_NMLN);
- (void) strncpy(n->version, kver_version, _SYS_NMLN);
+ (void) strncpy(n->release, kver.osrelease, _SYS_NMLN);
+ (void) strncpy(n->version, kver.version, _SYS_NMLN);
(void) strncpy(n->machine, real_utsname.machine, _SYS_NMLN);
return 0;
}
diff --git a/pkgtools/libkver/files/lib/shlib_version b/pkgtools/libkver/files/lib/shlib_version
index 3193e686d08..125979da08b 100644
--- a/pkgtools/libkver/files/lib/shlib_version
+++ b/pkgtools/libkver/files/lib/shlib_version
@@ -1,4 +1,4 @@
-# $NetBSD: shlib_version,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $
+# $NetBSD: shlib_version,v 1.2 2003/12/13 17:45:59 seb Exp $
-major=0
+major=1
minor=0
diff --git a/pkgtools/libkver/files/sysctl/Makefile b/pkgtools/libkver/files/sysctl/Makefile
index c4bf6d881b4..f8e8d3d0944 100644
--- a/pkgtools/libkver/files/sysctl/Makefile
+++ b/pkgtools/libkver/files/sysctl/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $
+# $NetBSD: Makefile,v 1.2 2003/12/13 17:45:59 seb Exp $
MKMAN= no
@@ -6,8 +6,6 @@ MKMAN= no
.PATH: ${BSDSRCDIR}/sbin/sysctl
-BINDIR= /sbin
-
.include "${BSDSRCDIR}/sbin/sysctl/Makefile"
LDADD+= ${.CURDIR}/../lib/libkver.a