update from LBL (Chris, Craig and Steve)
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 5 May 1992 08:05:05 +0000 (00:05 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 5 May 1992 08:05:05 +0000 (00:05 -0800)
SCCS-vsn: usr.sbin/kvm_mkdb/kvm_mkdb.c 5.15
SCCS-vsn: usr.sbin/kvm_mkdb/nlist.c 5.6

usr/src/usr.sbin/kvm_mkdb/kvm_mkdb.c
usr/src/usr.sbin/kvm_mkdb/nlist.c

index 6bd47c4..c7ccc29 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)kvm_mkdb.c 5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)kvm_mkdb.c 5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -21,20 +21,22 @@ static char sccsid[] = "@(#)kvm_mkdb.c      5.14 (Berkeley) %G%";
 #include <db.h>
 #include <errno.h>
 #include <stdio.h>
 #include <db.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <paths.h>
 
 #include <string.h>
 #include <paths.h>
 
-char *tmp;
-#define basename(cp)   ((tmp=rindex((cp), '/')) ? tmp+1 : (cp))
+#include "extern.h"
 
 
+static void usage __P(());
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int optind;
        DB *db;
        int ch;
        DB *db;
        int ch;
-       char *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN];
+       char *p, *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN];
 
        while ((ch = getopt(argc, argv, "")) != EOF)
                switch((char)ch) {
 
        while ((ch = getopt(argc, argv, "")) != EOF)
                switch((char)ch) {
@@ -48,13 +50,20 @@ main(argc, argv)
        if (argc > 1)
                usage();
 
        if (argc > 1)
                usage();
 
+       /* If the existing db file matches the currently running kernel, exit */
+       if (testdb())
+               exit(0);
+
+#define        basename(cp)    ((p = rindex((cp), '/')) != NULL ? p + 1 : (cp))
        nlistpath = argc > 1 ? argv[0] : _PATH_UNIX;
        nlistname = basename(nlistpath);
 
        nlistpath = argc > 1 ? argv[0] : _PATH_UNIX;
        nlistname = basename(nlistpath);
 
-       (void)sprintf(dbtemp, "%skvm_%s.tmp", _PATH_VARRUN, nlistname);
-       (void)sprintf(dbname, "%skvm_%s.db", _PATH_VARRUN, nlistname);
+       (void)snprintf(dbtemp, sizeof(dbtemp), "%skvm_%s.tmp",
+           _PATH_VARDB, nlistname);
+       (void)snprintf(dbname, sizeof(dbname), "%skvm_%s.db",
+           _PATH_VARDB, nlistname);
        (void)umask(0);
        (void)umask(0);
-       db = dbopen(dbtemp, O_CREAT|O_WRONLY|O_EXCL,
+       db = dbopen(dbtemp, O_CREAT|O_EXLOCK|O_TRUNC|O_WRONLY,
            S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL);
        if (!db) {
                (void)fprintf(stderr,
            S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL);
        if (!db) {
                (void)fprintf(stderr,
@@ -71,6 +80,7 @@ main(argc, argv)
        exit(0);
 }
 
        exit(0);
 }
 
+void
 error(n)
        char *n;
 {
 error(n)
        char *n;
 {
@@ -84,6 +94,7 @@ error(n)
        exit(1);
 }
 
        exit(1);
 }
 
+void
 usage()
 {
        (void)fprintf(stderr, "usage: kvm_mkdb [file]\n");
 usage()
 {
        (void)fprintf(stderr, "usage: kvm_mkdb [file]\n");
index 9c41c65..b996daf 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)nlist.c    5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)nlist.c    5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -21,12 +21,18 @@ static char sccsid[] = "@(#)nlist.c 5.5 (Berkeley) %G%";
 #include <string.h>
 #include <stdlib.h>
 
 #include <string.h>
 #include <stdlib.h>
 
+#include "extern.h"
+
 typedef struct nlist NLIST;
 #define        _strx   n_un.n_strx
 #define        _name   n_un.n_name
 
 typedef struct nlist NLIST;
 #define        _strx   n_un.n_strx
 #define        _name   n_un.n_name
 
+static void badread __P((int, char *));
+static void badfmt __P((char *));
+
 static char *kfile;
 
 static char *kfile;
 
+void
 create_knlist(name, db)
        char *name;
        DB *db;
 create_knlist(name, db)
        char *name;
        DB *db;
@@ -46,7 +52,7 @@ create_knlist(name, db)
        /* Read in exec structure. */
        nr = read(fd, (char *)&ebuf, sizeof(struct exec));
        if (nr != sizeof(struct exec))
        /* Read in exec structure. */
        nr = read(fd, (char *)&ebuf, sizeof(struct exec));
        if (nr != sizeof(struct exec))
-               badfmt(nr, "no exec header");
+               badfmt("no exec header");
 
        /* Check magic number and symbol count. */
        if (N_BADMAG(ebuf))
 
        /* Check magic number and symbol count. */
        if (N_BADMAG(ebuf))
@@ -95,27 +101,24 @@ create_knlist(name, db)
                if ((db->put)(db, &key, &data, 0))
                        error("put");
 
                if ((db->put)(db, &key, &data, 0))
                        error("put");
 
-               if (!strncmp((char *)key.data, VRS_SYM, sizeof(VRS_SYM) - 1)) {
-                       off_t cur_off, rel_off, vers_off;
-
-                       /* Offset relative to start of text image in VM. */
-                       rel_off = nbuf.n_value & ~KERNBASE;
-#ifdef tahoe
-                       /*
-                        * On tahoe, first 0x800 is reserved for communication
-                        * with the console processor.
-                        */
-                       rel_off -= 0x800;
+               if (strcmp((char *)key.data, VRS_SYM) == 0) {
+                       off_t cur_off, voff;
+#ifndef KERNTEXTOFF
+#define KERNTEXTOFF KERNBASE
 #endif
                        /*
 #endif
                        /*
-                        * When loaded, data is rounded to next page cluster
-                        * after text, but not in file.
+                        * Calculate offset relative to a normal (non-kernel)
+                        * a.out.  KERNTEXTOFF is where the kernel is really
+                        * loaded; N_TXTADDR is where a normal file is loaded.
+                        * From there, locate file offset in text or data.
                         */
                         */
-                       rel_off -= CLBYTES - (ebuf.a_text % CLBYTES);
-                       vers_off = N_TXTOFF(ebuf) + rel_off;
-
+                       voff = nbuf.n_value - KERNTEXTOFF + N_TXTADDR(ebuf);
+                       if ((nbuf.n_type & N_TYPE) == N_TEXT)
+                               voff += N_TXTOFF(ebuf) - N_TXTADDR(ebuf);
+                       else
+                               voff += N_DATOFF(ebuf) - N_DATADDR(ebuf);
                        cur_off = ftell(fp);
                        cur_off = ftell(fp);
-                       if (fseek(fp, vers_off, SEEK_SET) == -1)
+                       if (fseek(fp, voff, SEEK_SET) == -1)
                                badfmt("corrupted string table");
 
                        /*
                                badfmt("corrupted string table");
 
                        /*
@@ -143,6 +146,7 @@ create_knlist(name, db)
        (void)fclose(fp);
 }
 
        (void)fclose(fp);
 }
 
+static void
 badread(nr, p)
        int nr;
        char *p;
 badread(nr, p)
        int nr;
        char *p;
@@ -152,6 +156,7 @@ badread(nr, p)
        badfmt(p);
 }
 
        badfmt(p);
 }
 
+static void
 badfmt(p)
        char *p;
 {
 badfmt(p)
        char *p;
 {