summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorseb <seb@pkgsrc.org>2003-12-13 17:45:59 +0000
committerseb <seb@pkgsrc.org>2003-12-13 17:45:59 +0000
commit6c9b1b3c9a6542cec3895aaf9857385e3f59d2e4 (patch)
treec4a8d9ae9b868abbbe2deba585dc05c3b3b484c3 /pkgtools
parent92b0ce7f2701bd37ff5f65871c06bb379abea0ec (diff)
downloadpkgsrc-6c9b1b3c9a6542cec3895aaf9857385e3f59d2e4.tar.gz
Update to version 0.4.
Libkver is now run-time configurable, see installed kver(3), it now installs in LOCALBASE and uses install/deinstall scripts to replace/restore /sbin/sysctl if needed.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/libkver/DEINSTALL12
-rw-r--r--pkgtools/libkver/DESCR2
-rw-r--r--pkgtools/libkver/INSTALL12
-rw-r--r--pkgtools/libkver/Makefile26
-rw-r--r--pkgtools/libkver/PLIST9
-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
12 files changed, 249 insertions, 101 deletions
diff --git a/pkgtools/libkver/DEINSTALL b/pkgtools/libkver/DEINSTALL
new file mode 100644
index 00000000000..4ffdaf91618
--- /dev/null
+++ b/pkgtools/libkver/DEINSTALL
@@ -0,0 +1,12 @@
+# $NetBSD: DEINSTALL,v 1.1 2003/12/13 17:45:59 seb Exp $
+
+HAS_SYSCTL=@HAS_SYSCTL@
+
+case ${STAGE} in
+DEINSTALL)
+ if ${HAS_SYSCTL} && [ -f /sbin/sysctl.pre-${PKGBASE} ]; then
+ ${RM} -f /sbin/sysctl && \
+ ${MV} /sbin/sysctl.pre-${PKGBASE} /sbin/sysctl && \
+ ${ECHO} "/sbin/sysctl.pre-${PKGBASE} has been restored as /sbin/sysctl"
+ fi
+esac
diff --git a/pkgtools/libkver/DESCR b/pkgtools/libkver/DESCR
index aae0d0b0db9..ea6b6664ac6 100644
--- a/pkgtools/libkver/DESCR
+++ b/pkgtools/libkver/DESCR
@@ -2,7 +2,7 @@ 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.
+those the library is configured to report.
This is useful for -among other things- building packages in
sandboxed/chrooted environment for a different NetBSD release than the
diff --git a/pkgtools/libkver/INSTALL b/pkgtools/libkver/INSTALL
new file mode 100644
index 00000000000..8e39a5ea3e0
--- /dev/null
+++ b/pkgtools/libkver/INSTALL
@@ -0,0 +1,12 @@
+# $NetBSD: INSTALL,v 1.1 2003/12/13 17:45:59 seb Exp $
+
+HAS_SYSCTL=@HAS_SYSCTL@
+
+case ${STAGE} in
+POST-INSTALL)
+ if ${HAS_SYSCTL}; then
+ ${MV} /sbin/sysctl /sbin/sysctl.pre-${PKGBASE} && \
+ ${CP} -p ${PKG_PREFIX}/sbin/sysctl /sbin/sysctl && \
+ ${ECHO} "/sbin/sysctl has been moved as /sbin/sysctl.pre-${PKGBASE}"
+ fi
+esac
diff --git a/pkgtools/libkver/Makefile b/pkgtools/libkver/Makefile
index e27d57c391d..86e8272dc86 100644
--- a/pkgtools/libkver/Makefile
+++ b/pkgtools/libkver/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2003/10/27 20:31:42 seb Exp $
+# $NetBSD: Makefile,v 1.8 2003/12/13 17:45:59 seb Exp $
DISTNAME= libkver-${VERSION}
CATEGORIES= pkgtools
@@ -10,24 +10,38 @@ MAINTAINER= seb@NetBSD.org
COMMENT= Shared library and sysctl(1) replacement to override system version
USE_BUILDLINK2= # defined
+USE_PKGINSTALL= YES
NO_PKGTOOLS_REQD_CHECK= # defined
NO_CHECKSUM= # defined
NO_MTREE= # defined
-NO_PKG_REGISTER= # defined
-NO_PACKAGE= Deinstallation is not permitted
-VERSION= 0.3
+VERSION= 0.4
ONLY_FOR_PLATFORM= NetBSD-*-*
.include "../../mk/bsd.prefs.mk"
-.if defined(KVER_OSRELEASE)
-MAKE_ENV+= KVER_OSRELEASE=${KVER_OSRELEASE}
+LDD_SYSCTL!= ldd /sbin/sysctl 2>&1
+MAKE_ENV+= LDD_SYSCTL=${LDD_SYSCTL:Q} # save another ldd run
+.if empty(LDD_SYSCTL:M*libc*)
+PLIST_SUBST+= HAS_SYSCTL=
+FILES_SUBST+= HAS_SYSCTL=true
+.else
+PLIST_SUBST+= HAS_SYSCTL="@comment "
+FILES_SUBST+= HAS_SYSCTL=false
.endif
+INSTALL_EXTRA_TMPL+= ${.CURDIR}/INSTALL
+DEINSTALL_EXTRA_TMPL+= ${.CURDIR}/DEINSTALL
+
do-extract:
@${CP} -Rp ${FILESDIR} ${WRKSRC}
+pre-install:
+ ${INSTALL_DATA_DIR} ${PREFIX}/lib
+.if empty(LDD_SYSCTL:M*libc*)
+ ${INSTALL_DATA_DIR} ${PREFIX}/sbin
+.endif
+
.include "../../mk/bsd.pkg.mk"
diff --git a/pkgtools/libkver/PLIST b/pkgtools/libkver/PLIST
index eeb35fd5f85..1303710dbb6 100644
--- a/pkgtools/libkver/PLIST
+++ b/pkgtools/libkver/PLIST
@@ -1 +1,8 @@
-@comment $NetBSD: PLIST,v 1.1.1.1 2003/07/11 14:50:37 seb Exp $
+@comment $NetBSD: PLIST,v 1.2 2003/12/13 17:45:59 seb Exp $
+lib/libkver.a
+lib/libkver.so
+lib/libkver.so.1
+lib/libkver.so.1.0
+man/cat3/kver.0
+man/man3/kver.3
+${HAS_SYSCTL}sbin/sysctl
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