Get offset of `_version' right for sparc.

Remove temporary file on error exit.
Some general cleanup.
This commit is contained in:
pk 1993-12-02 20:55:47 +00:00
parent 10e08ca597
commit 6ff21e941b
2 changed files with 39 additions and 6 deletions

View File

@ -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 <sys/param.h>
@ -51,9 +51,16 @@ static char rcsid[] = "$Id: kvm_mkdb.c,v 1.4 1993/08/01 17:59:21 mycroft Exp $";
#include <string.h>
#include <paths.h>
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");

View File

@ -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 <sys/param.h>
@ -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);
}