diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-24 04:51:24 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-24 04:51:24 +0000 |
commit | 9a1ab4e5a3149672a0bfe95b3eff1a52e5bf02c7 (patch) | |
tree | 3464b648f324d29ed2242d6c7396f38b336aa6a1 /usr.sbin/kvm_mkdb | |
parent | 0c81a87831da1ed22e5f869cc36e2e87bf4efc03 (diff) |
Better fallback from /dev/ksyms to /bsd if there are problems with an nlist of /dev/ksyms
Diffstat (limited to 'usr.sbin/kvm_mkdb')
-rw-r--r-- | usr.sbin/kvm_mkdb/kvm_mkdb.c | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/usr.sbin/kvm_mkdb/kvm_mkdb.c b/usr.sbin/kvm_mkdb/kvm_mkdb.c index 1222e6f9b53..36555ec0f07 100644 --- a/usr.sbin/kvm_mkdb/kvm_mkdb.c +++ b/usr.sbin/kvm_mkdb/kvm_mkdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_mkdb.c,v 1.6 1998/10/06 18:09:50 millert Exp $ */ +/* $OpenBSD: kvm_mkdb.c,v 1.7 1999/03/24 04:51:23 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "from: @(#)kvm_mkdb.c 8.3 (Berkeley) 5/4/95"; #else -static char *rcsid = "$OpenBSD: kvm_mkdb.c,v 1.6 1998/10/06 18:09:50 millert Exp $"; +static char *rcsid = "$OpenBSD: kvm_mkdb.c,v 1.7 1999/03/24 04:51:23 millert Exp $"; #endif #endif /* not lint */ @@ -67,7 +67,8 @@ static char *rcsid = "$OpenBSD: kvm_mkdb.c,v 1.6 1998/10/06 18:09:50 millert Exp #include "extern.h" -static void usage __P((void)); +void usage __P((void)); +int kvm_mkdb __P((char *, char *, int)); HASHINFO openinfo = { 4096, /* bsize */ @@ -83,10 +84,9 @@ main(argc, argv) int argc; char *argv[]; { - DB *db; struct rlimit rl; - int fd, ch, verbose = 0; - char *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN]; + int rval, ch, verbose = 0; + char *nlistpath, *nlistname; /* Increase our data size to the max if we can. */ if (getrlimit(RLIMIT_DATA, &rl) == 0) { @@ -113,14 +113,33 @@ main(argc, argv) /* If no kernel specified use _PATH_KSYMS and fall back to _PATH_UNIX */ if (argc > 0) { nlistpath = argv[0]; - if ((fd = open(nlistpath, O_RDONLY, 0)) == -1) - err(1, "can't open %s", nlistpath); + nlistname = basename(argv[0]); + rval = kvm_mkdb(nlistpath, nlistname, verbose); } else { - if ((fd = open((nlistpath = _PATH_KSYMS), O_RDONLY, 0)) == -1 && - (fd = open((nlistpath = _PATH_UNIX), O_RDONLY, 0)) == -1) - err(1, "can't open %s", nlistpath); + nlistname = basename(_PATH_UNIX); + nlistpath = _PATH_KSYMS; + if ((rval = kvm_mkdb(nlistpath, nlistname, verbose)) != 0) { + nlistpath = _PATH_UNIX; + rval = kvm_mkdb(nlistpath, nlistname, verbose); + } + } + exit(rval); +} + +int +kvm_mkdb(nlistpath, nlistname, verbose) + char *nlistpath; + char *nlistname; + int verbose; +{ + DB *db; + int fd; + char dbtemp[MAXPATHLEN], dbname[MAXPATHLEN]; + + if ((fd = open(nlistpath, O_RDONLY, 0)) == -1) { + warn("can't open %s", nlistpath); + return(1); } - nlistname = argc > 0 ? basename(argv[0]) : basename(_PATH_UNIX); (void)snprintf(dbtemp, sizeof(dbtemp), "%skvm_%s.tmp", _PATH_VARDB, nlistname); @@ -128,28 +147,37 @@ main(argc, argv) _PATH_VARDB, nlistname); /* If the existing db file matches the currently running kernel, exit */ - if (testdb(dbname)) - exit(0); + if (testdb(dbname)) { + warnx("%s already up to date", dbname); + return(0); + } else if (verbose) warnx("rebuilding %s", dbname); (void)umask(0); db = dbopen(dbtemp, O_CREAT | O_EXLOCK | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, DB_HASH, &openinfo); - if (db == NULL) - err(1, "can't dbopen %s", dbtemp); + if (db == NULL) { + warn("can't dbopen %s", dbtemp); + return(1); + } if (create_knlist(nlistpath, fd, db) != 0) { (void)unlink(dbtemp); - errx(1, "cannot determine executable type of %s", nlistpath); + warn("cannot determine executable type of %s", nlistpath); + return(1); } if (db->close(db)) { warn("can't dbclose %s", dbtemp); (void)unlink(dbtemp); - exit(1); + return(1); } - if (rename(dbtemp, dbname)) - err(1, "rename %s to %s", dbtemp, dbname); - exit(0); + if (rename(dbtemp, dbname)) { + warn("rename %s to %s", dbtemp, dbname); + (void)unlink(dbtemp); + return(1); + } + + return(0); } void |