2001-12-17 18:39:43 +03:00
|
|
|
/* $NetBSD: main.c,v 1.61 2001/12/17 15:39:43 atatat Exp $ */
|
1996-03-03 20:21:25 +03:00
|
|
|
|
1996-03-17 09:29:19 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratories.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-04-28 10:54:58 +04:00
|
|
|
*
|
|
|
|
* from: @(#)main.c 8.1 (Berkeley) 6/6/93
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1997-10-18 11:58:56 +04:00
|
|
|
#ifndef MAKE_BOOTSTRAP
|
|
|
|
#include <sys/cdefs.h>
|
2000-10-02 23:57:23 +04:00
|
|
|
#define COPYRIGHT(x) __COPYRIGHT(x)
|
|
|
|
#else
|
|
|
|
#define COPYRIGHT(x) static const char copyright[] = x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
|
1997-10-18 11:58:56 +04:00
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1996-09-01 00:58:16 +04:00
|
|
|
#include <sys/param.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ctype.h>
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2001-12-17 18:39:43 +03:00
|
|
|
#include <vis.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "config.h"
|
1997-05-25 22:42:54 +04:00
|
|
|
#include "sem.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-06-28 08:41:36 +04:00
|
|
|
int vflag; /* verbose output */
|
2001-07-01 06:46:47 +04:00
|
|
|
int Pflag; /* pack locators */
|
1998-06-28 08:41:36 +04:00
|
|
|
|
2000-10-02 23:48:34 +04:00
|
|
|
int yyparse(void);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-10-08 15:33:40 +04:00
|
|
|
#ifndef MAKE_BOOTSTRAP
|
1997-10-10 14:27:53 +04:00
|
|
|
extern int yydebug;
|
2000-10-08 15:33:40 +04:00
|
|
|
#endif
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
static struct hashtab *mkopttab;
|
|
|
|
static struct nvlist **nextopt;
|
|
|
|
static struct nvlist **nextmkopt;
|
1997-01-31 06:12:30 +03:00
|
|
|
static struct nvlist **nextfsopt;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2000-10-02 23:48:34 +04:00
|
|
|
static void dependopts(void);
|
|
|
|
static void do_depend(struct nvlist *);
|
|
|
|
static void stop(void);
|
|
|
|
static int do_option(struct hashtab *, struct nvlist ***,
|
|
|
|
const char *, const char *, const char *);
|
|
|
|
static int crosscheck(void);
|
|
|
|
static int badstar(void);
|
|
|
|
int main(int, char **);
|
|
|
|
static int mksymlinks(void);
|
|
|
|
static int mkident(void);
|
|
|
|
static int hasparent(struct devi *);
|
|
|
|
static int cfcrosscheck(struct config *, const char *, struct nvlist *);
|
|
|
|
void defopt(struct hashtab *ht, const char *fname,
|
|
|
|
struct nvlist *opts, struct nvlist *deps);
|
|
|
|
|
2001-12-17 18:39:43 +03:00
|
|
|
#define LOGCONFIG_LARGE "INCLUDE_CONFIG_FILE"
|
|
|
|
#define LOGCONFIG_SMALL "INCLUDE_JUST_CONFIG"
|
|
|
|
|
|
|
|
static void logconfig_start(void);
|
|
|
|
static void logconfig_end(void);
|
|
|
|
static FILE *cfg;
|
|
|
|
static struct timespec cfgtime;
|
|
|
|
|
2000-10-02 23:48:34 +04:00
|
|
|
int badfilename(const char *fname);
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2001-02-21 02:51:59 +03:00
|
|
|
const char *progname;
|
1999-04-02 10:36:30 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
main(int argc, char **argv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
char *p;
|
1996-09-01 00:58:16 +04:00
|
|
|
const char *last_component;
|
1995-04-28 10:54:58 +04:00
|
|
|
int pflag, ch;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-02-21 02:51:59 +03:00
|
|
|
setprogname(argv[0]);
|
1999-04-02 10:36:30 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
pflag = 0;
|
2001-07-01 06:46:47 +04:00
|
|
|
while ((ch = getopt(argc, argv, "DPgpvb:s:")) != -1) {
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (ch) {
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2000-10-08 15:33:40 +04:00
|
|
|
#ifndef MAKE_BOOTSTRAP
|
1997-10-10 14:27:53 +04:00
|
|
|
case 'D':
|
|
|
|
yydebug = 1;
|
|
|
|
break;
|
2000-10-08 15:33:40 +04:00
|
|
|
#endif
|
1997-10-10 14:27:53 +04:00
|
|
|
|
2001-07-01 06:46:47 +04:00
|
|
|
case 'P':
|
|
|
|
Pflag = 1;
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'g':
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* In addition to DEBUG, you probably wanted to
|
|
|
|
* set "options KGDB" and maybe others. We could
|
|
|
|
* do that for you, but you really should just
|
|
|
|
* put them in the config file.
|
|
|
|
*/
|
|
|
|
(void)fputs(
|
|
|
|
"-g is obsolete (use makeoptions DEBUG=\"-g\")\n",
|
|
|
|
stderr);
|
|
|
|
goto usage;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'p':
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Essentially the same as makeoptions PROF="-pg",
|
|
|
|
* but also changes the path from ../../compile/FOO
|
1996-11-02 04:02:56 +03:00
|
|
|
* to ../../compile/FOO.PROF; i.e., compile a
|
1995-04-28 10:54:58 +04:00
|
|
|
* profiling kernel based on a typical "regular"
|
|
|
|
* kernel.
|
|
|
|
*
|
|
|
|
* Note that if you always want profiling, you
|
|
|
|
* can (and should) use a "makeoptions" line.
|
|
|
|
*/
|
|
|
|
pflag = 1;
|
1993-04-10 16:11:55 +04:00
|
|
|
break;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1998-06-28 08:41:36 +04:00
|
|
|
case 'v':
|
|
|
|
vflag = 1;
|
|
|
|
break;
|
|
|
|
|
1996-09-01 00:58:16 +04:00
|
|
|
case 'b':
|
|
|
|
builddir = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
srcdir = optarg;
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
goto usage;
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
1996-09-01 00:58:16 +04:00
|
|
|
if (argc > 1) {
|
1995-04-28 10:54:58 +04:00
|
|
|
usage:
|
2001-07-01 06:46:47 +04:00
|
|
|
(void)fputs("usage: config [-Ppv] [-s srcdir] [-b builddir] sysname\n", stderr);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-09-01 00:58:16 +04:00
|
|
|
conffile = (argc == 1) ? argv[0] : "CONFIG";
|
1995-04-28 10:54:58 +04:00
|
|
|
if (firstfile(conffile)) {
|
|
|
|
(void)fprintf(stderr, "config: cannot read %s: %s\n",
|
|
|
|
conffile, strerror(errno));
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(2);
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Init variables.
|
|
|
|
*/
|
|
|
|
minmaxusers = 1;
|
|
|
|
maxmaxusers = 10000;
|
|
|
|
initintern();
|
|
|
|
initfiles();
|
|
|
|
initsem();
|
2000-01-25 04:16:00 +03:00
|
|
|
ident = NULL;
|
1995-04-28 10:54:58 +04:00
|
|
|
devbasetab = ht_new();
|
1996-03-17 05:08:22 +03:00
|
|
|
devatab = ht_new();
|
1995-04-28 10:54:58 +04:00
|
|
|
selecttab = ht_new();
|
|
|
|
needcnttab = ht_new();
|
|
|
|
opttab = ht_new();
|
|
|
|
mkopttab = ht_new();
|
1997-01-31 06:12:30 +03:00
|
|
|
fsopttab = ht_new();
|
1998-02-19 03:27:00 +03:00
|
|
|
deffstab = ht_new();
|
1997-02-03 00:12:30 +03:00
|
|
|
defopttab = ht_new();
|
1998-06-24 15:20:54 +04:00
|
|
|
defparamtab = ht_new();
|
|
|
|
defflagtab = ht_new();
|
1998-01-12 10:37:40 +03:00
|
|
|
optfiletab = ht_new();
|
1995-04-28 10:54:58 +04:00
|
|
|
nextopt = &options;
|
|
|
|
nextmkopt = &mkoptions;
|
1997-01-31 06:12:30 +03:00
|
|
|
nextfsopt = &fsoptions;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle profiling (must do this before we try to create any
|
|
|
|
* files).
|
|
|
|
*/
|
1996-09-01 00:58:16 +04:00
|
|
|
last_component = strrchr(conffile, '/');
|
|
|
|
last_component = (last_component) ? last_component + 1 : conffile;
|
1995-04-28 10:54:58 +04:00
|
|
|
if (pflag) {
|
1996-09-01 00:58:16 +04:00
|
|
|
p = emalloc(strlen(last_component) + 17);
|
|
|
|
(void)sprintf(p, "../compile/%s.PROF", last_component);
|
1995-04-28 10:54:58 +04:00
|
|
|
(void)addmkoption(intern("PROF"), "-pg");
|
|
|
|
(void)addoption(intern("GPROF"), NULL);
|
1996-09-01 00:58:16 +04:00
|
|
|
} else {
|
|
|
|
p = emalloc(strlen(last_component) + 13);
|
|
|
|
(void)sprintf(p, "../compile/%s", last_component);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-09-01 00:58:16 +04:00
|
|
|
defbuilddir = (argc == 0) ? "." : p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Parse config file (including machine definitions).
|
|
|
|
*/
|
2001-12-17 18:39:43 +03:00
|
|
|
logconfig_start();
|
1993-03-21 12:45:37 +03:00
|
|
|
if (yyparse())
|
1995-04-28 10:54:58 +04:00
|
|
|
stop();
|
2001-12-17 18:39:43 +03:00
|
|
|
logconfig_end();
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1998-06-10 08:33:31 +04:00
|
|
|
/*
|
|
|
|
* Deal with option dependencies.
|
|
|
|
*/
|
|
|
|
dependopts();
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Fix (as in `set firmly in place') files.
|
|
|
|
*/
|
|
|
|
if (fixfiles())
|
|
|
|
stop();
|
|
|
|
|
1997-10-10 14:27:53 +04:00
|
|
|
/*
|
|
|
|
* Fix objects and libraries.
|
|
|
|
*/
|
|
|
|
if (fixobjects())
|
|
|
|
stop();
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Perform cross-checking.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
if (maxusers == 0) {
|
|
|
|
if (defmaxusers) {
|
|
|
|
(void)printf("maxusers not specified; %d assumed\n",
|
|
|
|
defmaxusers);
|
|
|
|
maxusers = defmaxusers;
|
|
|
|
} else {
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"config: need \"maxusers\" line\n");
|
|
|
|
errors++;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-01-31 06:12:30 +03:00
|
|
|
if (fsoptions == NULL) {
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"config: need at least one \"file-system\" line\n");
|
|
|
|
errors++;
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
if (crosscheck() || errors)
|
|
|
|
stop();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Squeeze things down and finish cross-checks (STAR checks must
|
|
|
|
* run after packing).
|
|
|
|
*/
|
|
|
|
pack();
|
|
|
|
if (badstar())
|
|
|
|
stop();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ready to go. Build all the various files.
|
|
|
|
*/
|
|
|
|
if (mksymlinks() || mkmakefile() || mkheaders() || mkswap() ||
|
2000-01-24 02:37:42 +03:00
|
|
|
mkioconf() || mkident())
|
1995-04-28 10:54:58 +04:00
|
|
|
stop();
|
|
|
|
(void)printf("Don't forget to run \"make depend\"\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1998-06-10 08:33:31 +04:00
|
|
|
/*
|
|
|
|
* Set any options that are implied by other options.
|
|
|
|
*/
|
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
dependopts(void)
|
1998-06-10 08:33:31 +04:00
|
|
|
{
|
|
|
|
struct nvlist *nv, *opt;
|
|
|
|
|
|
|
|
for (nv = options; nv != NULL; nv = nv->nv_next) {
|
1998-06-30 07:30:56 +04:00
|
|
|
if ((opt = find_declared_option(nv->nv_name)) != NULL) {
|
1998-06-10 08:33:31 +04:00
|
|
|
for (opt = opt->nv_ptr; opt != NULL;
|
|
|
|
opt = opt->nv_next) {
|
|
|
|
do_depend(opt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
do_depend(struct nvlist *nv)
|
1998-06-10 08:33:31 +04:00
|
|
|
{
|
|
|
|
struct nvlist *nextnv;
|
|
|
|
|
1999-09-22 18:23:03 +04:00
|
|
|
if (nv != NULL && !(nv->nv_flags & NV_DEPENDED)) {
|
|
|
|
nv->nv_flags |= NV_DEPENDED;
|
1998-06-10 08:33:31 +04:00
|
|
|
if (ht_lookup(opttab, nv->nv_name) == NULL)
|
|
|
|
addoption(nv->nv_name, NULL);
|
1998-06-30 07:30:56 +04:00
|
|
|
if ((nextnv = find_declared_option(nv->nv_name)) != NULL)
|
1998-06-10 08:33:31 +04:00
|
|
|
do_depend(nextnv->nv_ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Make a symlink for "machine" so that "#include <machine/foo.h>" works,
|
|
|
|
* and for the machine's CPU architecture, so that works as well.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
mksymlinks(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-04-28 10:54:58 +04:00
|
|
|
int ret;
|
1996-09-01 00:58:16 +04:00
|
|
|
char *p, buf[MAXPATHLEN];
|
|
|
|
const char *q;
|
2001-06-08 16:47:06 +04:00
|
|
|
struct nvlist *nv;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-09-01 00:58:16 +04:00
|
|
|
sprintf(buf, "arch/%s/include", machine);
|
|
|
|
p = sourcepath(buf);
|
1999-07-30 00:08:59 +04:00
|
|
|
ret = unlink("machine");
|
1999-07-31 09:22:05 +04:00
|
|
|
if (ret && errno != ENOENT)
|
1999-07-30 00:08:59 +04:00
|
|
|
(void)fprintf(stderr, "config: unlink(machine): %s\n",
|
|
|
|
strerror(errno));
|
1996-09-01 00:58:16 +04:00
|
|
|
ret = symlink(p, "machine");
|
1995-04-28 10:54:58 +04:00
|
|
|
if (ret)
|
1996-09-01 00:58:16 +04:00
|
|
|
(void)fprintf(stderr, "config: symlink(machine -> %s): %s\n",
|
|
|
|
p, strerror(errno));
|
1998-10-05 23:50:40 +04:00
|
|
|
free(p);
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
if (machinearch != NULL) {
|
1996-09-01 00:58:16 +04:00
|
|
|
sprintf(buf, "arch/%s/include", machinearch);
|
|
|
|
p = sourcepath(buf);
|
|
|
|
q = machinearch;
|
1995-04-28 10:54:58 +04:00
|
|
|
} else {
|
1999-07-09 10:44:58 +04:00
|
|
|
p = estrdup("machine");
|
1996-09-01 00:58:16 +04:00
|
|
|
q = machine;
|
1993-04-10 16:11:55 +04:00
|
|
|
}
|
1999-07-30 00:08:59 +04:00
|
|
|
ret = unlink(q);
|
1999-07-31 09:22:05 +04:00
|
|
|
if (ret && errno != ENOENT)
|
1999-07-30 00:08:59 +04:00
|
|
|
(void)fprintf(stderr, "config: unlink(%s): %s\n",
|
|
|
|
q, strerror(errno));
|
1996-09-01 00:58:16 +04:00
|
|
|
ret = symlink(p, q);
|
1995-04-28 10:54:58 +04:00
|
|
|
if (ret)
|
|
|
|
(void)fprintf(stderr, "config: symlink(%s -> %s): %s\n",
|
1996-09-01 00:58:16 +04:00
|
|
|
q, p, strerror(errno));
|
1995-04-28 10:54:58 +04:00
|
|
|
free(p);
|
|
|
|
|
2001-06-08 16:47:06 +04:00
|
|
|
for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
|
|
|
|
q = nv->nv_name;
|
|
|
|
sprintf(buf, "arch/%s/include", q);
|
|
|
|
p = sourcepath(buf);
|
|
|
|
ret = unlink(q);
|
|
|
|
if (ret && errno != ENOENT)
|
|
|
|
(void)fprintf(stderr, "config: unlink(%s): %s\n",
|
|
|
|
q, strerror(errno));
|
|
|
|
ret = symlink(p, q);
|
|
|
|
if (ret)
|
|
|
|
(void)fprintf(stderr, "config: symlink(%s -> %s): %s\n",
|
|
|
|
q, p, strerror(errno));
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __dead void
|
2000-10-02 23:48:34 +04:00
|
|
|
stop(void)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
|
|
|
(void)fprintf(stderr, "*** Stop.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1998-02-19 03:27:00 +03:00
|
|
|
/*
|
|
|
|
* Define one or more file systems. If file system options file name is
|
|
|
|
* specified, a preprocessor #define for that file system will be placed
|
|
|
|
* in that file. In this case, only one file system may be specified.
|
|
|
|
* Otherwise, no preprocessor #defines will be generated.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
deffilesystem(const char *fname, struct nvlist *fses)
|
1998-02-19 03:27:00 +03:00
|
|
|
{
|
|
|
|
struct nvlist *nv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark these options as ones to skip when creating the Makefile.
|
|
|
|
*/
|
|
|
|
for (nv = fses; nv != NULL; nv = nv->nv_next) {
|
|
|
|
if (ht_insert(defopttab, nv->nv_name, nv)) {
|
|
|
|
error("file system or option `%s' already defined",
|
|
|
|
nv->nv_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Also mark it as a valid file system, which may be
|
|
|
|
* used in "file-system" directives in the config
|
|
|
|
* file.
|
|
|
|
*/
|
|
|
|
if (ht_insert(deffstab, nv->nv_name, nv))
|
|
|
|
panic("file system `%s' already in table?!",
|
|
|
|
nv->nv_name);
|
|
|
|
|
|
|
|
if (fname != NULL) {
|
|
|
|
/*
|
|
|
|
* Only one file system allowed in this case.
|
|
|
|
*/
|
|
|
|
if (nv->nv_next != NULL) {
|
|
|
|
error("only one file system per option "
|
|
|
|
"file may be specified");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ht_insert(optfiletab, fname, nv)) {
|
|
|
|
error("option file `%s' already exists",
|
|
|
|
fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
/*
|
|
|
|
* Sanity check a file name.
|
|
|
|
*/
|
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
badfilename(const char *fname)
|
1998-06-24 15:20:54 +04:00
|
|
|
{
|
|
|
|
const char *n;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're putting multiple options into one file. Sanity
|
|
|
|
* check the file name.
|
|
|
|
*/
|
|
|
|
if (strchr(fname, '/') != NULL) {
|
|
|
|
error("option file name contains a `/'");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((n = strrchr(fname, '.')) == NULL || strcmp(n, ".h") != 0) {
|
|
|
|
error("option file name does not end in `.h'");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-30 07:30:56 +04:00
|
|
|
/*
|
|
|
|
* Search for a defined option (defopt, filesystem, etc), and if found,
|
|
|
|
* return the option's struct nvlist.
|
|
|
|
*/
|
|
|
|
struct nvlist *
|
2000-10-02 23:48:34 +04:00
|
|
|
find_declared_option(const char *name)
|
1998-06-30 07:30:56 +04:00
|
|
|
{
|
|
|
|
struct nvlist *option = NULL;
|
|
|
|
|
|
|
|
if ((option = ht_lookup(defopttab, name)) != NULL ||
|
|
|
|
(option = ht_lookup(defparamtab, name)) != NULL ||
|
|
|
|
(option = ht_lookup(defflagtab, name)) != NULL ||
|
|
|
|
(option = ht_lookup(fsopttab, name)) != NULL) {
|
|
|
|
return (option);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-02-03 00:12:30 +03:00
|
|
|
/*
|
1998-01-12 10:37:40 +03:00
|
|
|
* Define one or more standard options. If an option file name is specified,
|
|
|
|
* place all options in one file with the specified name. Otherwise, create
|
|
|
|
* an option file for each option.
|
1998-06-24 15:20:54 +04:00
|
|
|
* record the option information in the specified table.
|
1997-02-03 00:12:30 +03:00
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
defopt(struct hashtab *ht, const char *fname, struct nvlist *opts,
|
|
|
|
struct nvlist *deps)
|
1997-02-03 00:12:30 +03:00
|
|
|
{
|
1998-06-10 08:33:31 +04:00
|
|
|
struct nvlist *nv, *nextnv, *oldnv;
|
|
|
|
const char *name, *n;
|
1997-10-18 11:58:56 +04:00
|
|
|
char *p, c;
|
1997-02-03 00:12:30 +03:00
|
|
|
char low[500];
|
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
if (fname != NULL && badfilename(fname)) {
|
|
|
|
return;
|
1998-06-10 08:33:31 +04:00
|
|
|
}
|
|
|
|
|
1997-02-03 00:12:30 +03:00
|
|
|
/*
|
1998-01-12 10:37:40 +03:00
|
|
|
* Mark these options as ones to skip when creating the Makefile.
|
1997-02-03 00:12:30 +03:00
|
|
|
*/
|
1998-01-12 10:37:40 +03:00
|
|
|
for (nv = opts; nv != NULL; nv = nextnv) {
|
|
|
|
nextnv = nv->nv_next;
|
1998-06-30 07:30:56 +04:00
|
|
|
|
|
|
|
/* An option name can be declared at most once. */
|
|
|
|
if (DEFINED_OPTION(nv->nv_name)) {
|
|
|
|
error("file system or option `%s' already defined",
|
|
|
|
nv->nv_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
if (ht_insert(ht, nv->nv_name, nv)) {
|
1998-02-19 03:27:00 +03:00
|
|
|
error("file system or option `%s' already defined",
|
|
|
|
nv->nv_name);
|
1998-01-12 10:37:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fname == NULL) {
|
|
|
|
/*
|
|
|
|
* Each option will be going into its own file.
|
|
|
|
* Convert the option name to lower case. This
|
|
|
|
* lower case name will be used as the option
|
|
|
|
* file name.
|
|
|
|
*/
|
|
|
|
(void) strcpy(low, "opt_");
|
|
|
|
p = low + strlen(low);
|
|
|
|
for (n = nv->nv_name; (c = *n) != '\0'; n++)
|
|
|
|
*p++ = isupper(c) ? tolower(c) : c;
|
|
|
|
*p = '\0';
|
|
|
|
strcat(low, ".h");
|
1997-02-03 00:12:30 +03:00
|
|
|
|
1998-06-10 08:33:31 +04:00
|
|
|
name = intern(low);
|
|
|
|
} else {
|
|
|
|
name = fname;
|
1998-01-12 10:37:40 +03:00
|
|
|
}
|
1997-02-03 00:12:30 +03:00
|
|
|
|
1998-06-10 08:33:31 +04:00
|
|
|
/* Use nv_ptr to link any other options that are implied. */
|
|
|
|
nv->nv_ptr = deps;
|
1998-01-12 10:37:40 +03:00
|
|
|
|
1998-06-10 08:33:31 +04:00
|
|
|
/*
|
|
|
|
* Remove this option from the parameter list before adding
|
|
|
|
* it to the list associated with this option file.
|
|
|
|
*/
|
|
|
|
nv->nv_next = NULL;
|
1998-01-12 10:37:40 +03:00
|
|
|
|
1998-06-10 08:33:31 +04:00
|
|
|
/*
|
|
|
|
* Add this option file if we haven't seen it yet.
|
|
|
|
* Otherwise, append to the list of options already
|
|
|
|
* associated with this file.
|
|
|
|
*/
|
|
|
|
if ((oldnv = ht_lookup(optfiletab, name)) == NULL) {
|
|
|
|
(void)ht_insert(optfiletab, name, nv);
|
|
|
|
} else {
|
|
|
|
while (oldnv->nv_next != NULL)
|
|
|
|
oldnv = oldnv->nv_next;
|
|
|
|
oldnv->nv_next = nv;
|
|
|
|
}
|
1998-01-12 10:37:40 +03:00
|
|
|
}
|
1997-02-03 00:12:30 +03:00
|
|
|
}
|
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
/*
|
|
|
|
* Define one or more standard options. If an option file name is specified,
|
|
|
|
* place all options in one file with the specified name. Otherwise, create
|
|
|
|
* an option file for each option.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
defoption(const char *fname, struct nvlist *opts, struct nvlist *deps)
|
1998-06-24 15:20:54 +04:00
|
|
|
{
|
2000-10-02 23:48:34 +04:00
|
|
|
|
2001-12-06 02:42:37 +03:00
|
|
|
warn("The use of `defopt' is deprecated");
|
1998-06-24 15:20:54 +04:00
|
|
|
defopt(defopttab, fname, opts, deps);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define an option for which a value is required.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
defparam(const char *fname, struct nvlist *opts, struct nvlist *deps)
|
1998-06-24 15:20:54 +04:00
|
|
|
{
|
2000-10-02 23:48:34 +04:00
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
defopt(defparamtab, fname, opts, deps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define an option which must have a value, and which
|
|
|
|
* emits a "needs-flag" style output.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
defflag(const char *fname, struct nvlist *opts, struct nvlist *deps)
|
1998-06-24 15:20:54 +04:00
|
|
|
{
|
2000-10-02 23:48:34 +04:00
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
defopt(defflagtab, fname, opts, deps);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Add an option from "options FOO". Note that this selects things that
|
|
|
|
* are "optional foo".
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
addoption(const char *name, const char *value)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
const char *n;
|
|
|
|
char *p, c;
|
1995-04-28 10:54:58 +04:00
|
|
|
char low[500];
|
1998-06-24 15:20:54 +04:00
|
|
|
int is_fs, is_param, is_flag, is_opt, is_undecl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out how this option was declared (if at all.)
|
|
|
|
* XXX should use "params" and "flags" in config.
|
|
|
|
* XXX crying out for a type field in a unified hashtab.
|
|
|
|
*/
|
1998-06-30 07:30:56 +04:00
|
|
|
is_fs = OPT_FSOPT(name);
|
|
|
|
is_param = OPT_DEFPARAM(name);
|
|
|
|
is_opt = OPT_DEFOPT(name);
|
|
|
|
is_flag = OPT_DEFFLAG(name);
|
|
|
|
is_undecl = !DEFINED_OPTION(name);
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1998-02-19 09:13:51 +03:00
|
|
|
/* Make sure this is not a defined file system. */
|
1998-06-24 15:20:54 +04:00
|
|
|
if (is_fs) {
|
1998-02-19 09:13:51 +03:00
|
|
|
error("`%s' is a defined file system", name);
|
|
|
|
return;
|
|
|
|
}
|
1998-06-24 15:20:54 +04:00
|
|
|
/* A defparam must have a value */
|
|
|
|
if (is_param && value == NULL) {
|
|
|
|
error("option `%s' must have a value", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* A defflag must not have a value */
|
|
|
|
if (is_flag && value != NULL) {
|
|
|
|
error("option `%s' must not have a value", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-06-28 08:41:36 +04:00
|
|
|
if (is_undecl && vflag) {
|
1998-06-24 15:20:54 +04:00
|
|
|
warn("undeclared option `%s' added to IDENT", name);
|
|
|
|
}
|
1998-02-19 09:13:51 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
if (do_option(opttab, &nextopt, name, value, "options"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* make lowercase, then add to select table */
|
|
|
|
for (n = name, p = low; (c = *n) != '\0'; n++)
|
|
|
|
*p++ = isupper(c) ? tolower(c) : c;
|
|
|
|
*p = 0;
|
|
|
|
n = intern(low);
|
|
|
|
(void)ht_insert(selecttab, n, (void *)n);
|
|
|
|
}
|
|
|
|
|
1997-01-31 06:12:30 +03:00
|
|
|
/*
|
|
|
|
* Add a file system option. This routine simply inserts the name into
|
|
|
|
* a list of valid file systems, which is used to validate the root
|
|
|
|
* file system type. The name is then treated like a standard option.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
addfsoption(const char *name)
|
1997-01-31 06:12:30 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
const char *n;
|
|
|
|
char *p, c;
|
1998-02-19 09:13:51 +03:00
|
|
|
char low[500];
|
1997-01-31 06:12:30 +03:00
|
|
|
|
1998-02-19 03:27:00 +03:00
|
|
|
/* Make sure this is a defined file system. */
|
1998-06-30 07:30:56 +04:00
|
|
|
if (!OPT_FSOPT(name)) {
|
1998-02-19 03:27:00 +03:00
|
|
|
error("`%s' is not a defined file system", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-02-19 09:13:51 +03:00
|
|
|
/*
|
|
|
|
* Convert to lower case. This will be used in the select
|
1998-02-20 03:11:02 +03:00
|
|
|
* table, to verify root file systems, and when the initial
|
|
|
|
* VFS list is created.
|
1998-02-19 09:13:51 +03:00
|
|
|
*/
|
|
|
|
for (n = name, p = low; (c = *n) != '\0'; n++)
|
1997-01-31 06:12:30 +03:00
|
|
|
*p++ = isupper(c) ? tolower(c) : c;
|
|
|
|
*p = 0;
|
1998-02-19 09:13:51 +03:00
|
|
|
n = intern(low);
|
1997-01-31 06:12:30 +03:00
|
|
|
|
1998-02-19 09:13:51 +03:00
|
|
|
if (do_option(fsopttab, &nextfsopt, name, n, "file-system"))
|
1997-01-31 06:12:30 +03:00
|
|
|
return;
|
|
|
|
|
1998-02-20 03:11:02 +03:00
|
|
|
/*
|
|
|
|
* Add a lower-case version to the table for root file system
|
|
|
|
* verification.
|
|
|
|
*/
|
|
|
|
if (ht_insert(fsopttab, n, (void *)n))
|
|
|
|
panic("addfsoption: already in table");
|
|
|
|
|
1998-02-19 09:13:51 +03:00
|
|
|
/* Add to select table. */
|
|
|
|
(void)ht_insert(selecttab, n, (void *)n);
|
1997-01-31 06:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Add a "make" option.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
addmkoption(const char *name, const char *value)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
(void)do_option(mkopttab, &nextmkopt, name, value, "mkoptions");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a name=value pair to an option list. The value may be NULL.
|
|
|
|
*/
|
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
do_option(struct hashtab *ht, struct nvlist ***nppp, const char *name,
|
|
|
|
const char *value, const char *type)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist *nv;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1998-06-30 07:30:56 +04:00
|
|
|
/*
|
2001-11-28 08:03:31 +03:00
|
|
|
* If a defopt'ed or defflag'ed option was enabled but without
|
|
|
|
* an explicit value (always the case for defflag), supply a
|
|
|
|
* default value of 1, as for non-defopt options (where cc
|
|
|
|
* treats -DBAR as -DBAR=1.)
|
1998-06-30 07:30:56 +04:00
|
|
|
*/
|
2001-11-28 08:03:31 +03:00
|
|
|
if ((OPT_DEFOPT(name) || OPT_DEFFLAG(name)) && value == NULL)
|
1998-06-30 07:30:56 +04:00
|
|
|
value = "1";
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/* assume it will work */
|
1996-03-17 14:50:09 +03:00
|
|
|
nv = newnv(name, value, NULL, 0, NULL);
|
1995-04-28 10:54:58 +04:00
|
|
|
if (ht_insert(ht, name, nv) == 0) {
|
|
|
|
**nppp = nv;
|
|
|
|
*nppp = &nv->nv_next;
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
/* oops, already got that option */
|
|
|
|
nvfree(nv);
|
|
|
|
if ((nv = ht_lookup(ht, name)) == NULL)
|
|
|
|
panic("do_option");
|
1998-06-30 07:30:56 +04:00
|
|
|
if (nv->nv_str != NULL && !OPT_FSOPT(name))
|
1995-04-28 10:54:58 +04:00
|
|
|
error("already have %s `%s=%s'", type, name, nv->nv_str);
|
|
|
|
else
|
|
|
|
error("already have %s `%s'", type, name);
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-04-10 16:11:55 +04:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Return true if there is at least one instance of the given unit
|
1996-03-17 05:08:22 +03:00
|
|
|
* on the given device attachment (or any units, if unit == WILD).
|
1993-04-10 16:11:55 +04:00
|
|
|
*/
|
1996-03-17 05:08:22 +03:00
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
deva_has_instances(struct deva *deva, int unit)
|
1993-04-10 16:11:55 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devi *i;
|
1993-04-10 16:11:55 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
if (unit == WILD)
|
1996-03-17 05:08:22 +03:00
|
|
|
return (deva->d_ihead != NULL);
|
|
|
|
for (i = deva->d_ihead; i != NULL; i = i->i_asame)
|
1995-04-28 10:54:58 +04:00
|
|
|
if (unit == i->i_unit)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-03-17 05:08:22 +03:00
|
|
|
/*
|
|
|
|
* Return true if there is at least one instance of the given unit
|
|
|
|
* on the given base (or any units, if unit == WILD).
|
|
|
|
*/
|
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
devbase_has_instances(struct devbase *dev, int unit)
|
1996-03-17 05:08:22 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct deva *da;
|
1996-03-17 05:08:22 +03:00
|
|
|
|
|
|
|
for (da = dev->d_ahead; da != NULL; da = da->d_bsame)
|
|
|
|
if (deva_has_instances(da, unit))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
hasparent(struct devi *i)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist *nv;
|
1995-04-28 10:54:58 +04:00
|
|
|
int atunit = i->i_atunit;
|
|
|
|
|
1996-03-17 05:08:22 +03:00
|
|
|
/*
|
Fix PR 2218. As noted (both in mail from me included in the PR, and
in XXX-marked comments in the recent attachment changes), this was a
long-standing bug in config.
The problem: If a device is attached to a device via an attribute exported
by that device (i.e. foo* at bar0, where 'bar' exports an attribute that
'foo' attaches to), but the device attached to is not present in the
kernel configuration file, AND another device which exports an attribute
that 'foo' attaches to _is_ present (e.g. a device baz0, if one could
specify 'foo0 at baz0'), then: the configuration file will (incorrectly)
be accepted by config, and the resulting ioconf.c will include a bogus
cfdata entry for the device (in the example, 'foo*'). This typically
causes the resulting kernel to crash during autoconfiguration.
The solution: Be much more careful about keeping track of where a device
was attached, and, in particular, if a device was attached to another device,
_always_ keep track of what device it was attached to. Then, when
cross-checking, if the attached-to device isn't present, give up and do not
check attributes. Also, document the process much more thoroughly.
1996-03-17 10:05:50 +03:00
|
|
|
* We determine whether or not a device has a parent in in one
|
|
|
|
* of two ways:
|
|
|
|
* (1) If a parent device was named in the config file,
|
|
|
|
* i.e. cases (2) and (3) in sem.c:adddev(), then
|
|
|
|
* we search its devbase for a matching unit number.
|
|
|
|
* (2) If the device was attach to an attribute, then we
|
|
|
|
* search all attributes the device can be attached to
|
|
|
|
* for parents (with appropriate unit numebrs) that
|
|
|
|
* may be able to attach the device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case (1): A parent was named. Either it's configured, or not.
|
|
|
|
*/
|
|
|
|
if (i->i_atdev != NULL)
|
|
|
|
return (devbase_has_instances(i->i_atdev, atunit));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case (2): No parent was named. Look for devs that provide the attr.
|
1996-03-17 05:08:22 +03:00
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
if (i->i_atattr != NULL)
|
|
|
|
for (nv = i->i_atattr->a_refs; nv != NULL; nv = nv->nv_next)
|
1996-03-17 05:08:22 +03:00
|
|
|
if (devbase_has_instances(nv->nv_ptr, atunit))
|
1995-04-28 10:54:58 +04:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
cfcrosscheck(struct config *cf, const char *what, struct nvlist *nv)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devbase *dev;
|
|
|
|
struct devi *pd;
|
1997-05-25 22:42:54 +04:00
|
|
|
int errs, devunit;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1996-11-12 02:41:54 +03:00
|
|
|
if (maxpartitions <= 0)
|
|
|
|
panic("cfcrosscheck");
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
for (errs = 0; nv != NULL; nv = nv->nv_next) {
|
|
|
|
if (nv->nv_name == NULL)
|
|
|
|
continue;
|
|
|
|
dev = ht_lookup(devbasetab, nv->nv_name);
|
|
|
|
if (dev == NULL)
|
|
|
|
panic("cfcrosscheck(%s)", nv->nv_name);
|
1997-05-25 22:42:54 +04:00
|
|
|
if (has_attr(dev->d_attrs, s_ifnet))
|
|
|
|
devunit = nv->nv_ifunit; /* XXX XXX XXX */
|
|
|
|
else
|
|
|
|
devunit = minor(nv->nv_int) / maxpartitions;
|
|
|
|
if (devbase_has_instances(dev, devunit))
|
1996-03-17 05:08:22 +03:00
|
|
|
continue;
|
|
|
|
if (devbase_has_instances(dev, STAR) &&
|
1997-05-25 22:42:54 +04:00
|
|
|
devunit >= dev->d_umax)
|
1995-04-28 10:54:58 +04:00
|
|
|
continue;
|
|
|
|
for (pd = allpseudo; pd != NULL; pd = pd->i_next)
|
1997-05-25 22:42:54 +04:00
|
|
|
if (pd->i_base == dev && devunit < dev->d_umax &&
|
|
|
|
devunit >= 0)
|
1995-04-28 10:54:58 +04:00
|
|
|
goto loop;
|
|
|
|
(void)fprintf(stderr,
|
1998-05-22 23:29:00 +04:00
|
|
|
"%s:%d: %s says %s on %s, but there's no %s\n",
|
1995-04-28 10:54:58 +04:00
|
|
|
conffile, cf->cf_lineno,
|
|
|
|
cf->cf_name, what, nv->nv_str, nv->nv_str);
|
|
|
|
errs++;
|
|
|
|
loop:
|
2001-01-16 05:43:37 +03:00
|
|
|
;
|
1993-04-10 16:11:55 +04:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
return (errs);
|
1993-04-10 16:11:55 +04:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Cross-check the configuration: make sure that each target device
|
|
|
|
* or attribute (`at foo[0*?]') names at least one real device. Also
|
1997-06-12 19:03:09 +04:00
|
|
|
* see that the root and dump devices for all configurations are there.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
crosscheck(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devi *i;
|
|
|
|
struct config *cf;
|
1995-04-28 10:54:58 +04:00
|
|
|
int errs;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
errs = 0;
|
|
|
|
for (i = alldevi; i != NULL; i = i->i_next) {
|
|
|
|
if (i->i_at == NULL || hasparent(i))
|
|
|
|
continue;
|
|
|
|
xerror(conffile, i->i_lineno,
|
|
|
|
"%s at %s is orphaned", i->i_name, i->i_at);
|
1996-03-17 05:08:22 +03:00
|
|
|
(void)fprintf(stderr, " (%s %s declared)\n",
|
|
|
|
i->i_atunit == WILD ? "nothing matching" : "no",
|
|
|
|
i->i_at);
|
1995-04-28 10:54:58 +04:00
|
|
|
errs++;
|
|
|
|
}
|
|
|
|
if (allcf == NULL) {
|
|
|
|
(void)fprintf(stderr, "%s has no configurations!\n",
|
|
|
|
conffile);
|
|
|
|
errs++;
|
|
|
|
}
|
|
|
|
for (cf = allcf; cf != NULL; cf = cf->cf_next) {
|
1997-06-12 19:03:09 +04:00
|
|
|
if (cf->cf_root != NULL) { /* i.e., not root on ? */
|
1995-04-28 10:54:58 +04:00
|
|
|
errs += cfcrosscheck(cf, "root", cf->cf_root);
|
|
|
|
errs += cfcrosscheck(cf, "dumps", cf->cf_dump);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
return (errs);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-03-17 05:08:22 +03:00
|
|
|
* Check to see if there is a *'d unit with a needs-count file.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
badstar(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devbase *d;
|
|
|
|
struct deva *da;
|
|
|
|
struct devi *i;
|
|
|
|
int errs, n;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
errs = 0;
|
|
|
|
for (d = allbases; d != NULL; d = d->d_next) {
|
1996-03-17 05:08:22 +03:00
|
|
|
for (da = d->d_ahead; da != NULL; da = da->d_bsame)
|
|
|
|
for (i = da->d_ihead; i != NULL; i = i->i_asame) {
|
|
|
|
if (i->i_unit == STAR)
|
|
|
|
goto foundstar;
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
continue;
|
|
|
|
foundstar:
|
|
|
|
if (ht_lookup(needcnttab, d->d_name)) {
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"config: %s's cannot be *'d until its driver is fixed\n",
|
|
|
|
d->d_name);
|
|
|
|
errs++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (n = 0; i != NULL; i = i->i_alias)
|
|
|
|
if (!i->i_collapsed)
|
|
|
|
n++;
|
|
|
|
if (n < 1)
|
|
|
|
panic("badstar() n<1");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
return (errs);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-11-12 02:41:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify/create builddir if necessary, change to it, and verify srcdir.
|
|
|
|
* This will be called when we see the first include.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
setupdirs(void)
|
1996-11-12 02:41:54 +03:00
|
|
|
{
|
2000-12-15 01:14:45 +03:00
|
|
|
struct stat st;
|
1996-11-12 02:41:54 +03:00
|
|
|
|
2000-12-15 01:14:45 +03:00
|
|
|
/* srcdir must be specified if builddir is not specified or if
|
|
|
|
* no configuration filename was specified. */
|
1996-11-12 02:41:54 +03:00
|
|
|
if ((builddir || strcmp(defbuilddir, ".") == 0) && !srcdir) {
|
|
|
|
error("source directory must be specified");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcdir == NULL)
|
|
|
|
srcdir = "../../../..";
|
|
|
|
if (builddir == NULL)
|
|
|
|
builddir = defbuilddir;
|
|
|
|
|
|
|
|
if (stat(builddir, &st) != 0) {
|
|
|
|
if (mkdir(builddir, 0777)) {
|
|
|
|
(void)fprintf(stderr, "config: cannot create %s: %s\n",
|
|
|
|
builddir, strerror(errno));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
} else if (!S_ISDIR(st.st_mode)) {
|
|
|
|
(void)fprintf(stderr, "config: %s is not a directory\n",
|
|
|
|
builddir);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
if (chdir(builddir) != 0) {
|
|
|
|
(void)fprintf(stderr, "config: cannot change to %s\n",
|
|
|
|
builddir);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode)) {
|
|
|
|
(void)fprintf(stderr, "config: %s is not a directory\n",
|
|
|
|
srcdir);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
}
|
2000-01-24 02:37:42 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write identifier from "ident" directive into file, for
|
|
|
|
* newvers.sh to pick it up.
|
|
|
|
*/
|
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
mkident(void)
|
2000-01-24 02:37:42 +03:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
(void)unlink("ident");
|
|
|
|
|
|
|
|
if (ident == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if ((fp = fopen("ident", "w")) == NULL) {
|
|
|
|
(void)fprintf(stderr, "config: cannot write ident: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (vflag)
|
|
|
|
(void)printf("using ident '%s'\n", ident);
|
|
|
|
if (fprintf(fp, "%s\n", ident) < 0)
|
|
|
|
return (1);
|
|
|
|
(void)fclose(fp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2001-12-17 18:39:43 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
logconfig_start(void)
|
|
|
|
{
|
|
|
|
extern FILE *yyin;
|
|
|
|
char line[1024];
|
|
|
|
struct stat st;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (yyin == NULL || fstat(fileno(yyin), &st) == -1)
|
|
|
|
return;
|
|
|
|
cfgtime = st.st_mtimespec;
|
|
|
|
|
|
|
|
snprintf(line, sizeof(line), "config.tmp.XXXXXX");
|
|
|
|
if ((fd = mkstemp(line)) == -1 ||
|
|
|
|
(cfg = fdopen(fd, "r+")) == NULL) {
|
|
|
|
if (fd != -1) {
|
|
|
|
unlink(line);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
cfg = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unlink(line);
|
|
|
|
|
|
|
|
(void)fprintf(cfg, "#include \"opt_config.h\"\n");
|
|
|
|
(void)fprintf(cfg, "\n");
|
|
|
|
(void)fprintf(cfg, "/*\n");
|
|
|
|
(void)fprintf(cfg, " * Add either (or both) of\n");
|
|
|
|
(void)fprintf(cfg, " *\n");
|
|
|
|
(void)fprintf(cfg, " *\toptions %s\n", LOGCONFIG_LARGE);
|
|
|
|
(void)fprintf(cfg, " *\toptions %s\n", LOGCONFIG_SMALL);
|
|
|
|
(void)fprintf(cfg, " *\n");
|
|
|
|
(void)fprintf(cfg,
|
|
|
|
" * to your kernel config file to embed it in the resulting\n");
|
|
|
|
(void)fprintf(cfg,
|
|
|
|
" * kernel. The latter option does not include files that are\n");
|
|
|
|
(void)fprintf(cfg,
|
|
|
|
" * included (recursively) by your config file. The embedded\n");
|
|
|
|
(void)fprintf(cfg,
|
|
|
|
" * data be extracted by using the command:\n");
|
|
|
|
(void)fprintf(cfg, " *\n");
|
|
|
|
(void)fprintf(cfg,
|
|
|
|
" *\tstrings netbsd | sed -n 's/^_CFG_//p' | unvis\n");
|
|
|
|
(void)fprintf(cfg, " */\n");
|
|
|
|
(void)fprintf(cfg, "\n");
|
|
|
|
(void)fprintf(cfg, "#ifdef CONFIG_FILE\n");
|
|
|
|
(void)fprintf(cfg, "#if defined(%s) || defined(%s)\n\n",
|
|
|
|
LOGCONFIG_LARGE, LOGCONFIG_SMALL);
|
|
|
|
(void)fprintf(cfg,
|
|
|
|
"static const char config[] __attribute__((__unused__)) =\n\n");
|
|
|
|
|
|
|
|
(void)fprintf(cfg, "#ifdef %s\n\n", LOGCONFIG_LARGE);
|
|
|
|
(void)fprintf(cfg, "\"_CFG_### START CONFIG FILE \\\"%s\\\"\\n\"\n\n",
|
|
|
|
conffile);
|
|
|
|
(void)fprintf(cfg, "#endif /* %s */\n\n", LOGCONFIG_LARGE);
|
|
|
|
|
|
|
|
(void)fprintf(cfg, "\"");
|
|
|
|
logconfig_include(yyin, NULL);
|
|
|
|
(void)fprintf(cfg, "\"\n\n");
|
|
|
|
|
|
|
|
(void)fprintf(cfg, "#ifdef %s\n\n", LOGCONFIG_LARGE);
|
|
|
|
(void)fprintf(cfg, "\"_CFG_### END CONFIG FILE \\\"%s\\\"\n", conffile);
|
|
|
|
|
|
|
|
rewind(yyin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
logconfig_include(FILE *cf, const char *filename)
|
|
|
|
{
|
|
|
|
char line[1024], in[2048], *out;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (!cfg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fstat(fileno(cf), &st) == -1)
|
|
|
|
return;
|
|
|
|
if (cfgtime.tv_sec < st.st_mtimespec.tv_sec ||
|
|
|
|
(cfgtime.tv_sec == st.st_mtimespec.tv_sec &&
|
|
|
|
cfgtime.tv_nsec < st.st_mtimespec.tv_nsec))
|
|
|
|
cfgtime = st.st_mtimespec;
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
(void)fprintf(cfg, "_CFG_### (included from \\\"%s\\\")\n",
|
|
|
|
filename);
|
|
|
|
while (fgets(line, sizeof(line), cf) != NULL) {
|
|
|
|
(void)fprintf(cfg, "_CFG_");
|
|
|
|
if (filename)
|
|
|
|
(void)fprintf(cfg, "###> ");
|
|
|
|
strvis(in, line, VIS_TAB);
|
|
|
|
for (out = in; *out; out++)
|
|
|
|
switch (*out) {
|
|
|
|
case '"': case '\\':
|
|
|
|
(void)fputc('\\', cfg);
|
|
|
|
default:
|
|
|
|
(void)fputc(*out, cfg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filename)
|
|
|
|
(void)fprintf(cfg, "_CFG_### (end include \\\"%s\\\")\n",
|
|
|
|
filename);
|
|
|
|
|
|
|
|
rewind(cf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
logconfig_end(void)
|
|
|
|
{
|
|
|
|
char line[1024];
|
|
|
|
FILE *fp;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (!cfg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(void)fprintf(cfg, "\"\n");
|
|
|
|
(void)fprintf(cfg, "#endif /* %s */\n", LOGCONFIG_LARGE);
|
|
|
|
(void)fprintf(cfg, ";\n");
|
|
|
|
(void)fprintf(cfg, "#endif /* %s || %s */\n",
|
|
|
|
LOGCONFIG_LARGE, LOGCONFIG_SMALL);
|
|
|
|
(void)fprintf(cfg, "#endif /* CONFIG_FILE */\n");
|
|
|
|
rewind(cfg);
|
|
|
|
|
|
|
|
if (stat("config_file.h", &st) != -1) {
|
|
|
|
if (cfgtime.tv_sec < st.st_mtimespec.tv_sec ||
|
|
|
|
(cfgtime.tv_sec == st.st_mtimespec.tv_sec &&
|
|
|
|
cfgtime.tv_nsec < st.st_mtimespec.tv_nsec)) {
|
|
|
|
fclose(cfg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = fopen("config_file.h", "w");
|
|
|
|
while (fgets(line, sizeof(line), cfg) != NULL)
|
|
|
|
fputs(line, fp);
|
|
|
|
fclose(fp);
|
|
|
|
fclose(cfg);
|
|
|
|
}
|