diff options
author | seb <seb> | 2003-07-11 14:50:37 +0000 |
---|---|---|
committer | seb <seb> | 2003-07-11 14:50:37 +0000 |
commit | ef2f5b5fe98fa20c58af6ce6d88dacf9e3b522e7 (patch) | |
tree | d99abe91a17954ff6c7805c05614ff51ba88b62c /pkgtools | |
parent | 34a825f633f8ee784ad2a103ad02e36920e07916 (diff) | |
download | pkgsrc-ef2f5b5fe98fa20c58af6ce6d88dacf9e3b522e7.tar.gz |
Initial import of libkver version 0.1 into the NetBSD Packages Colelction.
This package provides a shared library and a replacement for
sysctl(1) (when needed i.e. when the original one is statically linked)
so that the real version numbers and strings of the running NetBSD
kernel as returned by sysctl(3) and uname(3) are overridden by
those fixed during compilation.
This is useful for -among other things- building packages in
sandboxed/chrooted environment for a different NetBSD release than the
system hosting the sandbox/chroot.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/libkver/DESCR | 9 | ||||
-rw-r--r-- | pkgtools/libkver/Makefile | 27 | ||||
-rw-r--r-- | pkgtools/libkver/PLIST | 1 | ||||
-rw-r--r-- | pkgtools/libkver/files/Makefile | 12 | ||||
-rw-r--r-- | pkgtools/libkver/files/Makefile.inc | 23 | ||||
-rw-r--r-- | pkgtools/libkver/files/lib/Makefile | 9 | ||||
-rw-r--r-- | pkgtools/libkver/files/lib/kver.c | 138 | ||||
-rw-r--r-- | pkgtools/libkver/files/lib/shlib_version | 4 | ||||
-rw-r--r-- | pkgtools/libkver/files/sysctl/Makefile | 15 |
9 files changed, 238 insertions, 0 deletions
diff --git a/pkgtools/libkver/DESCR b/pkgtools/libkver/DESCR new file mode 100644 index 00000000000..aae0d0b0db9 --- /dev/null +++ b/pkgtools/libkver/DESCR @@ -0,0 +1,9 @@ +This package provides a shared library and a replacement for +sysctl(1) (when needed i.e. when the original one is statically linked) +so that the real version numbers and strings of the running NetBSD +kernel as returned by sysctl(3) and uname(3) are overridden by +those fixed during compilation. + +This is useful for -among other things- building packages in +sandboxed/chrooted environment for a different NetBSD release than the +system hosting the sandbox/chroot. diff --git a/pkgtools/libkver/Makefile b/pkgtools/libkver/Makefile new file mode 100644 index 00000000000..5893808c59d --- /dev/null +++ b/pkgtools/libkver/Makefile @@ -0,0 +1,27 @@ +# $NetBSD: Makefile,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ + +DISTNAME= libkver-${VERSION} +CATEGORIES= pkgtools +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= seb@netbsd.org +#HOMEPAGE= +COMMENT= shared librarie and sysctl(1) replacement to override system version + +USE_BUILDLINK2= # defined + +NO_PKGTOOLS_REQD_CHECK= # defined +NO_CHECKSUM= # defined +NO_MTREE= # defined +NO_PKG_REGISTER= # defined +NO_PACKAGE= Deinstallation is not permitted + +VERSION= 0.1 + +ONLY_FOR_PLATFORM= NetBSD-*-* + +do-extract: + @${CP} -Rp ${FILESDIR} ${WRKSRC} + +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/libkver/PLIST b/pkgtools/libkver/PLIST new file mode 100644 index 00000000000..eeb35fd5f85 --- /dev/null +++ b/pkgtools/libkver/PLIST @@ -0,0 +1 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ diff --git a/pkgtools/libkver/files/Makefile b/pkgtools/libkver/files/Makefile new file mode 100644 index 00000000000..7691a3a9307 --- /dev/null +++ b/pkgtools/libkver/files/Makefile @@ -0,0 +1,12 @@ +# $NetBSD: Makefile,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ + +.include "${.CURDIR}/Makefile.inc" + +SUBDIR= lib + +LDD_SYSCTL!= ldd /sbin/sysctl 2>&1 +.if empty(LDD_SYSCTL:M*libc*) +SUBDIR+= sysctl +.endif + +.include <bsd.subdir.mk> diff --git a/pkgtools/libkver/files/Makefile.inc b/pkgtools/libkver/files/Makefile.inc new file mode 100644 index 00000000000..99f473f6731 --- /dev/null +++ b/pkgtools/libkver/files/Makefile.inc @@ -0,0 +1,23 @@ +# $NetBSD: Makefile.inc,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ + +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 +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 + +.if !empty(SUPPORTED_KVER_OSRELEASES:M${KVER_OSRELEASE}) +CFLAGS+= -D_KVER_OSREVISION=${KVER_OSREVISION.${KVER_OSRELEASE}} +.else +.BEGIN: + @echo "You must define KVER_OSRELEASE to be one of:" + @echo "${SUPPORTED_KVER_OSRELEASES}" + @false +.endif diff --git a/pkgtools/libkver/files/lib/Makefile b/pkgtools/libkver/files/lib/Makefile new file mode 100644 index 00000000000..c76f2a4fcc7 --- /dev/null +++ b/pkgtools/libkver/files/lib/Makefile @@ -0,0 +1,9 @@ +# $NetBSD: Makefile,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ + +NOPROFILE= # defined +NOLINT= # defined +USE_SHLIBDIR= yes +LIB= kver +SRCS= kver.c + +.include <bsd.lib.mk> diff --git a/pkgtools/libkver/files/lib/kver.c b/pkgtools/libkver/files/lib/kver.c new file mode 100644 index 00000000000..d3c1721766f --- /dev/null +++ b/pkgtools/libkver/files/lib/kver.c @@ -0,0 +1,138 @@ +/* $NetBSD: kver.c,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/utsname.h> +#include <assert.h> +#include <errno.h> +#include <string.h> + +#define KVER_VERSION_FMT "NetBSD %.6s (GENERIC) #0: %.40s root@localhost:/sys/arch/%.20s/compile/GENERIC %.20s" + +/* _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" +#else +#error You must define _KVER_OSREVISION +#endif + +static char *kver_osrelease = _KVER_OSRELEASE; +static char *kver_date = _KVER_DATE; +static int kver_osrevision = _KVER_OSREVISION; + +#define SYSCTL_STRING(oldp, oldlenp, str) \ + if (oldlenp) { \ + len = strlen(str) + 1; \ + if (!oldp) \ + *oldlenp = len; \ + else { \ + if (*oldlenp < len) { \ + r = ENOMEM; \ + len = *oldlenp; \ + } else \ + *oldlenp = len; \ + (void) strncpy(oldp, str, len); \ + } \ + } + +/* 6 chars for osrelease */ +/* 40 chars for the date string */ +/* 40 chars for 2 utsname.machine */ +#define KVER_VERSION_LEN (sizeof(KVER_VERSION_FMT) + 6 + 40 + 40 + 1) +static char kver_version[KVER_VERSION_LEN] = ""; +static struct utsname real_utsname; + +static void +kver_init(void) +{ + if (_uname(&real_utsname) != 0) + return; + snprintf(kver_version, KVER_VERSION_LEN, KVER_VERSION_FMT, + kver_osrelease, + kver_date, + real_utsname.machine, + real_utsname.machine); +} + +int +sysctl(int *name, u_int namelen, void *oldp, size_t * oldlenp, const void *newp, + size_t newlen) +{ + _DIAGASSERT(name != NULL); + + if (newp != (void *) NULL) + goto real; + + if (namelen != 2) { + errno = EINVAL; + return (-1); + } + + if (*kver_version == '\0') { + kver_init(); + if (*kver_version == '\0') + 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); + return (r); + case KERN_OSREV: + if (oldlenp) { + if (!oldp) + *oldlenp = sizeof(int); + else { + if (*oldlenp < sizeof(int)) + return (ENOMEM); + *oldlenp = sizeof(int); + *((int *) oldp) = kver_osrevision; + } + } + return (r); + case KERN_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); + } + (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->machine, real_utsname.machine, _SYS_NMLN); + return 0; +} diff --git a/pkgtools/libkver/files/lib/shlib_version b/pkgtools/libkver/files/lib/shlib_version new file mode 100644 index 00000000000..3193e686d08 --- /dev/null +++ b/pkgtools/libkver/files/lib/shlib_version @@ -0,0 +1,4 @@ +# $NetBSD: shlib_version,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ + +major=0 +minor=0 diff --git a/pkgtools/libkver/files/sysctl/Makefile b/pkgtools/libkver/files/sysctl/Makefile new file mode 100644 index 00000000000..c4bf6d881b4 --- /dev/null +++ b/pkgtools/libkver/files/sysctl/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $ + +MKMAN= no + +.include <bsd.own.mk> + +.PATH: ${BSDSRCDIR}/sbin/sysctl + +BINDIR= /sbin + +.include "${BSDSRCDIR}/sbin/sysctl/Makefile" + +LDADD+= ${.CURDIR}/../lib/libkver.a +CPPFLAGS+= -I${BSDSRCDIR}/sys +LDSTATIC?= -static |