From owner-svn-src-stable-8@FreeBSD.ORG Sun May 2 06:14:36 2010 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6E487106566B; Sun, 2 May 2010 06:14:36 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 5D0138FC13; Sun, 2 May 2010 06:14:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o426EaXd067657; Sun, 2 May 2010 06:14:36 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o426EaXY067653; Sun, 2 May 2010 06:14:36 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201005020614.o426EaXY067653@svn.freebsd.org> From: Warner Losh Date: Sun, 2 May 2010 06:14:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207491 - stable/8/usr.sbin/config X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2010 06:14:36 -0000 Author: imp Date: Sun May 2 06:14:36 2010 New Revision: 207491 URL: http://svn.freebsd.org/changeset/base/207491 Log: MFC r207260: 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. Modified: stable/8/usr.sbin/config/config.h stable/8/usr.sbin/config/main.c stable/8/usr.sbin/config/mkmakefile.c Directory Properties: stable/8/usr.sbin/config/ (props changed) Modified: stable/8/usr.sbin/config/config.h ============================================================================== --- stable/8/usr.sbin/config/config.h Sun May 2 04:16:39 2010 (r207490) +++ stable/8/usr.sbin/config/config.h Sun May 2 06:14:36 2010 (r207491) @@ -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: stable/8/usr.sbin/config/main.c ============================================================================== --- stable/8/usr.sbin/config/main.c Sun May 2 04:16:39 2010 (r207490) +++ stable/8/usr.sbin/config/main.c Sun May 2 06:14:36 2010 (r207491) @@ -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: stable/8/usr.sbin/config/mkmakefile.c ============================================================================== --- stable/8/usr.sbin/config/mkmakefile.c Sun May 2 04:16:39 2010 (r207490) +++ stable/8/usr.sbin/config/mkmakefile.c Sun May 2 06:14:36 2010 (r207491) @@ -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);