1 /* $NetBSD: kvm_mkdb.c,v 1.19 2003/08/07 11:25:23 agc Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 #include <sys/cdefs.h>
66 __COPYRIGHT("@(#) Copyright (c) 1990, 1993\
67 The Regents of the University of California. All rights reserved.");
72 static char sccsid
[] = "from: @(#)kvm_mkdb.c 8.3 (Berkeley) 5/4/95";
74 __RCSID("$NetBSD: kvm_mkdb.c,v 1.19 2003/08/07 11:25:23 agc Exp $");
78 #include <sys/param.h>
93 int main
__P((int, char **));
94 static void usage
__P((void));
100 2048 * 1024, /* cachesize */
106 static char *dbname
= NULL
;
107 static char dbtemp
[MAXPATHLEN
];
119 while ((ch
= getopt(argc
, argv
, "o:")) != -1)
135 if (dbname
== NULL
) {
136 dbname
= _PATH_KVMDB
;
138 } else if (strncmp(_PATH_KVMDB
, dbname
, sizeof(_PATH_KVMDB
)) == 0) {
143 * If the existing db file matches the currently running
152 * Check for useability of _PATH_KSYMS, if not
153 * then fallback to _PATH_UNIX.
154 * Should we complain if failure?
156 if ((fd
= open(_PATH_KSYMS
, O_RDONLY
)) >= 0) {
158 nlistpath
= _PATH_KSYMS
;
160 nlistpath
= _PATH_UNIX
;
164 (void)snprintf(dbtemp
, sizeof(dbtemp
), "%s.tmp", dbname
);
166 db
= dbopen(dbtemp
, O_CREAT
| O_EXLOCK
| O_TRUNC
| O_RDWR
,
167 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
, DB_HASH
, &openinfo
);
169 err(1, "%s", dbtemp
);
170 create_knlist(nlistpath
, db
);
177 if (rename(dbtemp
, dbname
)) {
178 warn("rename %s to %s", dbtemp
, dbname
);
187 (void)fprintf(stderr
, "usage: kvm_mkdb [-o database] [file]\n");