Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/usr.sbin/kvm_mkdb Pull up revision 1.8 (requested by ms...
details: https://anonhg.NetBSD.org/src/rev/b1dfc9afbab8
branches: netbsd-1-5
changeset: 491018:b1dfc9afbab8
user: he <he%NetBSD.org@localhost>
date: Fri Mar 30 22:03:46 2001 +0000
description:
Pull up revision 1.8 (requested by msaitoh):
Use sysctl instead of kmem groveling to fetch version string of
running kernel.
diffstat:
usr.sbin/kvm_mkdb/testdb.c | 41 +++++++++++++++++++----------------------
1 files changed, 19 insertions(+), 22 deletions(-)
diffs (81 lines):
diff -r b50a97fe57d0 -r b1dfc9afbab8 usr.sbin/kvm_mkdb/testdb.c
--- a/usr.sbin/kvm_mkdb/testdb.c Fri Mar 30 21:54:01 2001 +0000
+++ b/usr.sbin/kvm_mkdb/testdb.c Fri Mar 30 22:03:46 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: testdb.c,v 1.7 1997/10/18 08:49:36 lukem Exp $ */
+/* $NetBSD: testdb.c,v 1.7.12.1 2001/03/30 22:03:46 he Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -38,17 +38,20 @@
#if 0
static char sccsid[] = "from: @(#)testdb.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: testdb.c,v 1.7 1997/10/18 08:49:36 lukem Exp $");
+__RCSID("$NetBSD: testdb.c,v 1.7.12.1 2001/03/30 22:03:46 he Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/file.h>
+#include <sys/sysctl.h>
+#include <err.h>
#include <errno.h>
#include <limits.h>
#include <kvm.h>
#include <db.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <paths.h>
@@ -60,11 +63,12 @@
testdb()
{
DB *db;
- int cc, kd, ret, dbversionlen;
+ int kd, ret, dbversionlen;
DBT rec;
- struct nlist nitem;
char dbversion[_POSIX2_LINE_MAX];
- char kversion[_POSIX2_LINE_MAX];
+ char *kversion;
+ int mib[2];
+ size_t size;
ret = 0;
db = NULL;
@@ -86,23 +90,16 @@
dbversionlen = rec.size;
/* Read version string from kernel memory */
- rec.data = VRS_SYM;
- rec.size = sizeof(VRS_SYM) - 1;
- if ((db->get)(db, &rec, &rec, 0))
- goto close;
- if (rec.data == 0 || rec.size != sizeof(struct nlist))
- goto close;
- memmove(&nitem, rec.data, sizeof(nitem));
- /*
- * Theoretically possible for lseek to be seeking to -1. Not
- * that it's something to lie awake nights about, however.
- */
- errno = 0;
- if (lseek(kd, (off_t)nitem.n_value, SEEK_SET) == -1 && errno != 0)
- goto close;
- cc = read(kd, kversion, sizeof(kversion));
- if (cc < 0 || cc != sizeof(kversion))
- goto close;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_VERSION;
+ if (sysctl(mib, 2, NULL, &size, NULL, 0) == -1)
+ errx(1, "can't get size of kernel version string");
+
+ if ((kversion = malloc(size)) == NULL)
+ err(1, "couldn't allocate space for buffer data");
+
+ if (sysctl(mib, 2, kversion, &size, NULL, 0) == -1)
+ errx(1, "can't get kernel version string");
/* If they match, we win */
ret = memcmp(dbversion, kversion, dbversionlen) == 0;
Home |
Main Index |
Thread Index |
Old Index