Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Apr 2010 05:04:32 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r207260 - head/usr.sbin/config
Message-ID:  <201004270504.o3R54Xu0006743@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Tue Apr 27 05:04:32 2010
New Revision: 207260
URL: http://svn.freebsd.org/changeset/base/207260

Log:
  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

Modified:
  head/usr.sbin/config/config.h
  head/usr.sbin/config/main.c
  head/usr.sbin/config/mkmakefile.c

Modified: head/usr.sbin/config/config.h
==============================================================================
--- head/usr.sbin/config/config.h	Tue Apr 27 02:52:19 2010	(r207259)
+++ head/usr.sbin/config/config.h	Tue Apr 27 05:04:32 2010	(r207260)
@@ -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;
 

Modified: head/usr.sbin/config/main.c
==============================================================================
--- head/usr.sbin/config/main.c	Tue Apr 27 02:52:19 2010	(r207259)
+++ head/usr.sbin/config/main.c	Tue Apr 27 05:04:32 2010	(r207260)
@@ -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);
+}

Modified: head/usr.sbin/config/mkmakefile.c
==============================================================================
--- head/usr.sbin/config/mkmakefile.c	Tue Apr 27 02:52:19 2010	(r207259)
+++ head/usr.sbin/config/mkmakefile.c	Tue Apr 27 05:04:32 2010	(r207260)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004270504.o3R54Xu0006743>