summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2010-04-27 05:04:32 +0000
committerimp <imp@FreeBSD.org>2010-04-27 05:04:32 +0000
commit1b05a112d4cbea67db29b7df286106b4cde94e93 (patch)
treea2652595ec783ee7d8e499e3947ba8000e7f2d54 /usr.sbin/config
parentbba9d9c06c699a401091f437b2dced6938a6accc (diff)
downloadFreeBSD-src-1b05a112d4cbea67db29b7df286106b4cde94e93.zip
FreeBSD-src-1b05a112d4cbea67db29b7df286106b4cde94e93.tar.gz
Move checking the version up from Makefile generation to just after
we've parsed the config file. Makefile generation is too late if we've introduce changes to the syntax of the metafiles to warn about version skew, since we have to try to parse them and we get an parse error that's rather baffling to the user rather than a 'your config is too old, upgrade' which we should get. We have to defer doing it until after we've read the user's config file because we define machinename there. The version required to compile the kernel is encoded in Makefile.machinename. There's no real reason for this to be the case, but changing it now would introduce some logistical issues that I'd rather avoid for the moment. I intend to revisit this if we're still using config in FreeBSD 10. This also means that we cannot introduce any config metafile changes that result in a syntax error or other error for the user until 9.0 is released. Otherwise, we break the upgrade path, or at least reduce the usefulness of the error messages we generate. # This implies that the config file option mapping will need to be redone. MFC after: 3 days
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/config.h1
-rw-r--r--usr.sbin/config/main.c40
-rw-r--r--usr.sbin/config/mkmakefile.c45
3 files changed, 62 insertions, 24 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h
index ec19986..4abb567 100644
--- a/usr.sbin/config/config.h
+++ b/usr.sbin/config/config.h
@@ -179,6 +179,7 @@ void makehints(void);
void headers(void);
void cfgfile_add(const char *);
void cfgfile_removeall(void);
+FILE *open_makefile_template(void);
extern STAILQ_HEAD(device_head, device) dtab;
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 2b5e055..5cffed2 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -90,6 +90,7 @@ static void get_srcdir(void);
static void usage(void);
static void cleanheaders(char *);
static void kernconfdump(const char *);
+static void checkversion(void);
struct hdr_list {
char *h_name;
@@ -204,6 +205,7 @@ main(int argc, char **argv)
printf("cpu type must be specified\n");
exit(1);
}
+ checkversion();
/*
* make symbolic links in compilation directory
@@ -721,3 +723,41 @@ kernconfdump(const char *file)
}
fclose(fp);
}
+
+static void
+badversion(int versreq)
+{
+ fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
+ fprintf(stderr, "config version = %d, ", CONFIGVERS);
+ fprintf(stderr, "version required = %d\n\n", versreq);
+ fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
+ fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
+ fprintf(stderr, "before trying this again.\n\n");
+ fprintf(stderr, "If running the new config fails check your config\n");
+ fprintf(stderr, "file against the GENERIC or LINT config files for\n");
+ fprintf(stderr, "changes in config syntax, or option/device naming\n");
+ fprintf(stderr, "conventions\n\n");
+ exit(1);
+}
+
+static void
+checkversion(void)
+{
+ FILE *ifp;
+ char line[BUFSIZ];
+ int versreq;
+
+ ifp = open_makefile_template();
+ while (fgets(line, BUFSIZ, ifp) != 0) {
+ if (*line != '%')
+ continue;
+ if (strncmp(line, "%VERSREQ=", 9) != 0)
+ continue;
+ versreq = atoi(line + 9);
+ if (MAJOR_VERS(versreq) == MAJOR_VERS(CONFIGVERS) &&
+ versreq <= CONFIGVERS)
+ continue;
+ badversion(versreq);
+ }
+ fclose(ifp);
+}
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 7845089..b5a0e35 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -105,17 +105,14 @@ new_fent(void)
}
/*
- * Build the makefile from the skeleton
+ * Open the correct Makefile and return it, or error out.
*/
-void
-makefile(void)
+FILE *
+open_makefile_template(void)
{
- FILE *ifp, *ofp;
+ FILE *ifp;
char line[BUFSIZ];
- struct opt *op, *t;
- int versreq;
- read_files();
snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename);
ifp = fopen(line, "r");
if (ifp == 0) {
@@ -124,7 +121,21 @@ makefile(void)
}
if (ifp == 0)
err(1, "%s", line);
+ return (ifp);
+}
+/*
+ * Build the makefile from the skeleton
+ */
+void
+makefile(void)
+{
+ FILE *ifp, *ofp;
+ char line[BUFSIZ];
+ struct opt *op, *t;
+
+ read_files();
+ ifp = open_makefile_template();
ofp = fopen(path("Makefile.new"), "w");
if (ofp == 0)
err(1, "%s", path("Makefile.new"));
@@ -156,23 +167,9 @@ makefile(void)
do_rules(ofp);
else if (eq(line, "%CLEAN\n"))
do_clean(ofp);
- else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) {
- versreq = atoi(line + sizeof("%VERSREQ=") - 1);
- if (MAJOR_VERS(versreq) != MAJOR_VERS(CONFIGVERS) ||
- versreq > CONFIGVERS) {
- fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
- fprintf(stderr, "config version = %d, ", CONFIGVERS);
- fprintf(stderr, "version required = %d\n\n", versreq);
- fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
- fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
- fprintf(stderr, "before trying this again.\n\n");
- fprintf(stderr, "If running the new config fails check your config\n");
- fprintf(stderr, "file against the GENERIC or LINT config files for\n");
- fprintf(stderr, "changes in config syntax, or option/device naming\n");
- fprintf(stderr, "conventions\n\n");
- exit(1);
- }
- } else
+ else if (strncmp(line, "%VERSREQ=", 9) == 0)
+ line[0] = '\0'; /* handled elsewhere */
+ else
fprintf(stderr,
"Unknown %% construct in generic makefile: %s",
line);
OpenPOWER on IntegriCloud