From 6ff21e941bb01fee2b30d4edb606f408f800ea58 Mon Sep 17 00:00:00 2001 From: pk Date: Thu, 2 Dec 1993 20:55:47 +0000 Subject: [PATCH] Get offset of `_version' right for sparc. Remove temporary file on error exit. Some general cleanup. --- usr.sbin/kvm_mkdb/kvm_mkdb.c | 26 ++++++++++++++++++++++---- usr.sbin/kvm_mkdb/nlist.c | 19 +++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/usr.sbin/kvm_mkdb/kvm_mkdb.c b/usr.sbin/kvm_mkdb/kvm_mkdb.c index 8b2e8ba8c5e4..d491dd0a6f3c 100644 --- a/usr.sbin/kvm_mkdb/kvm_mkdb.c +++ b/usr.sbin/kvm_mkdb/kvm_mkdb.c @@ -39,7 +39,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)kvm_mkdb.c 5.11 (Berkeley) 4/27/91";*/ -static char rcsid[] = "$Id: kvm_mkdb.c,v 1.4 1993/08/01 17:59:21 mycroft Exp $"; +static char rcsid[] = "$Id: kvm_mkdb.c,v 1.5 1993/12/02 20:55:47 pk Exp $"; #endif /* not lint */ #include @@ -51,9 +51,16 @@ static char rcsid[] = "$Id: kvm_mkdb.c,v 1.4 1993/08/01 17:59:21 mycroft Exp $"; #include #include -char *tmp; +static int laundry; +static char dbtemp[MAXPATHLEN], dbname[MAXPATHLEN]; + +static char *tmp; #define basename(cp) ((tmp=rindex((cp), '/')) ? tmp+1 : (cp)) +static void usage(); +void cleanup(); + +int main(argc, argv) int argc; char **argv; @@ -61,7 +68,7 @@ main(argc, argv) extern int optind; DB *db; int ch; - char *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN]; + char *nlistpath, *nlistname; while ((ch = getopt(argc, argv, "")) != EOF) switch((char)ch) { @@ -85,6 +92,7 @@ main(argc, argv) "kvm_mkdb: %s: %s\n", dbtemp, strerror(errno)); exit(1); } + laundry = 1; create_knlist(nlistpath, db); (void)(db->close)(db); if (rename(dbtemp, dbname)) { @@ -92,9 +100,10 @@ main(argc, argv) dbtemp, dbname, strerror(errno)); exit(1); } - exit(0); + return(0); } +void error(n) char *n; { @@ -105,9 +114,18 @@ error(n) if (n) (void)fprintf(stderr, "%s: ", n); (void)fprintf(stderr, "%s\n", strerror(sverr)); + cleanup(); exit(1); } +void +cleanup() +{ + if (laundry) + (void)unlink(dbtemp); +} + +static void usage() { (void)fprintf(stderr, "usage: kvm_mkdb [file]\n"); diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c index 267a3d5c31fd..6685bf319f15 100644 --- a/usr.sbin/kvm_mkdb/nlist.c +++ b/usr.sbin/kvm_mkdb/nlist.c @@ -33,7 +33,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)nlist.c 5.4 (Berkeley) 4/27/91";*/ -static char rcsid[] = "$Id: nlist.c,v 1.6 1993/08/02 18:17:24 mycroft Exp $"; +static char rcsid[] = "$Id: nlist.c,v 1.7 1993/12/02 20:55:52 pk Exp $"; #endif /* not lint */ #include @@ -54,6 +54,11 @@ typedef struct nlist NLIST; static char *kfile; +extern void cleanup(); +static void badread(); +static void badfmt(); + +void create_knlist(name, db) char *name; DB *db; @@ -139,6 +144,12 @@ create_knlist(name, db) #ifdef vax rel_off = nbuf.n_value & ~KERNBASE; #endif +#ifdef sparc + /* + * On sparc, first 0x4000 is reserved for ? + */ + rel_off = (nbuf.n_value & ~KERNBASE) - 0x4000; +#endif #ifdef i386 /* * XXX: This is a KLUGE to handle the kernel being @@ -154,7 +165,8 @@ create_knlist(name, db) * When loaded, data is rounded to next page cluster * after text, but not in file. */ - rel_off -= CLBYTES - (ebuf.a_text % CLBYTES); + if (ebuf.a_text % CLBYTES) + rel_off -= CLBYTES - (ebuf.a_text % CLBYTES); vers_off = N_TXTOFF(ebuf) + rel_off; cur_off = ftell(fp); @@ -186,6 +198,7 @@ create_knlist(name, db) (void)fclose(fp); } +static void badread(nr, p) int nr; char *p; @@ -195,10 +208,12 @@ badread(nr, p) badfmt(p); } +static void badfmt(p) char *p; { (void)fprintf(stderr, "kvm_mkdb: %s: %s: %s\n", kfile, p, strerror(EFTYPE)); + cleanup(); exit(1); }