]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - usr.sbin/config/main.c
Add missed mergeinfo.
[FreeBSD/stable/8.git] / usr.sbin / config / main.c
1 /*
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef lint
31 static const char copyright[] =
32 "@(#) Copyright (c) 1980, 1993\n\
33         The Regents of the University of California.  All rights reserved.\n";
34 #endif /* not lint */
35
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)main.c      8.1 (Berkeley) 6/6/93";
39 #endif
40 static const char rcsid[] =
41   "$FreeBSD$";
42 #endif /* not lint */
43
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <sys/sbuf.h>
47 #include <sys/file.h>
48 #include <sys/mman.h>
49 #include <sys/param.h>
50
51 #include <assert.h>
52 #include <ctype.h>
53 #include <err.h>
54 #include <stdio.h>
55 #include <string.h>
56 #include <sysexits.h>
57 #include <unistd.h>
58 #include <dirent.h>
59 #include "y.tab.h"
60 #include "config.h"
61 #include "configvers.h"
62
63 #ifndef TRUE
64 #define TRUE    (1)
65 #endif
66
67 #ifndef FALSE
68 #define FALSE   (0)
69 #endif
70
71 #define CDIR    "../compile/"
72
73 char *  PREFIX;
74 char    destdir[MAXPATHLEN];
75 char    srcdir[MAXPATHLEN];
76
77 int     debugging;
78 int     profiling;
79 int     found_defaults;
80 int     incignore;
81
82 /*
83  * Preserve old behaviour in INCLUDE_CONFIG_FILE handling (files are included
84  * literally).
85  */
86 int     filebased = 0;
87
88 static void configfile(void);
89 static void get_srcdir(void);
90 static void usage(void);
91 static void cleanheaders(char *);
92 static void kernconfdump(const char *);
93 static void checkversion(void);
94
95 struct hdr_list {
96         char *h_name;
97         struct hdr_list *h_next;
98 } *htab;
99
100 /*
101  * Config builds a set of files for building a UNIX
102  * system given a description of the desired system.
103  */
104 int
105 main(int argc, char **argv)
106 {
107
108         struct stat buf;
109         int ch, len;
110         char *p;
111         char xxx[MAXPATHLEN];
112         char *kernfile;
113         int printmachine;
114
115         printmachine = 0;
116         kernfile = NULL;
117         while ((ch = getopt(argc, argv, "Cd:gmpVx:")) != -1)
118                 switch (ch) {
119                 case 'C':
120                         filebased = 1;
121                         break;
122                 case 'm':
123                         printmachine = 1;
124                         break;
125                 case 'd':
126                         if (*destdir == '\0')
127                                 strlcpy(destdir, optarg, sizeof(destdir));
128                         else
129                                 errx(EXIT_FAILURE, "directory already set");
130                         break;
131                 case 'g':
132                         debugging++;
133                         break;
134                 case 'p':
135                         profiling++;
136                         break;
137                 case 'V':
138                         printf("%d\n", CONFIGVERS);
139                         exit(0);
140                 case 'x':
141                         kernfile = optarg;
142                         break;
143                 case '?':
144                 default:
145                         usage();
146                 }
147         argc -= optind;
148         argv += optind;
149
150         if (kernfile != NULL) {
151                 kernconfdump(kernfile);
152                 exit(EXIT_SUCCESS);
153         }
154
155         if (argc != 1)
156                 usage();
157
158         PREFIX = *argv;
159         if (stat(PREFIX, &buf) != 0 || !S_ISREG(buf.st_mode))
160                 err(2, "%s", PREFIX);
161         if (freopen("DEFAULTS", "r", stdin) != NULL) {
162                 found_defaults = 1;
163                 yyfile = "DEFAULTS";
164         } else {
165                 if (freopen(PREFIX, "r", stdin) == NULL)
166                         err(2, "%s", PREFIX);
167                 yyfile = PREFIX;
168         }
169         if (*destdir != '\0') {
170                 len = strlen(destdir);
171                 while (len > 1 && destdir[len - 1] == '/')
172                         destdir[--len] = '\0';
173                 get_srcdir();
174         } else {
175                 strlcpy(destdir, CDIR, sizeof(destdir));
176                 strlcat(destdir, PREFIX, sizeof(destdir));
177         }
178
179         SLIST_INIT(&cputype);
180         SLIST_INIT(&mkopt);
181         SLIST_INIT(&opt);
182         SLIST_INIT(&rmopts);
183         STAILQ_INIT(&cfgfiles);
184         STAILQ_INIT(&dtab);
185         STAILQ_INIT(&fntab);
186         STAILQ_INIT(&ftab);
187         STAILQ_INIT(&hints);
188         if (yyparse())
189                 exit(3);
190
191         /*
192          * Ensure that required elements (machine, cpu, ident) are present.
193          */
194         if (machinename == NULL) {
195                 printf("Specify machine type, e.g. ``machine i386''\n");
196                 exit(1);
197         }
198         if (ident == NULL) {
199                 printf("no ident line specified\n");
200                 exit(1);
201         }
202         if (SLIST_EMPTY(&cputype)) {
203                 printf("cpu type must be specified\n");
204                 exit(1);
205         }
206         checkversion();
207
208         if (printmachine) {
209                 printf("%s\t%s\n",machinename,machinearch);
210                 exit(0);
211         }
212
213         /* Make compile directory */
214         p = path((char *)NULL);
215         if (stat(p, &buf)) {
216                 if (mkdir(p, 0777))
217                         err(2, "%s", p);
218         } else if (!S_ISDIR(buf.st_mode))
219                 errx(EXIT_FAILURE, "%s isn't a directory", p);
220
221         /*
222          * make symbolic links in compilation directory
223          * for "sys" (to make genassym.c work along with #include <sys/xxx>)
224          * and similarly for "machine".
225          */
226         if (*srcdir == '\0')
227                 (void)snprintf(xxx, sizeof(xxx), "../../include");
228         else
229                 (void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
230                     srcdir, machinename);
231         (void) unlink(path("machine"));
232         (void) symlink(xxx, path("machine"));
233         if (strcmp(machinename, machinearch) != 0) {
234                 /*
235                  * make symbolic links in compilation directory for
236                  * machinearch, if it is different than machinename.
237                  */
238                 if (*srcdir == '\0')
239                         (void)snprintf(xxx, sizeof(xxx), "../../../%s/include",
240                             machinearch);
241                 else
242                         (void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
243                             srcdir, machinearch);
244                 (void) unlink(path(machinearch));
245                 (void) symlink(xxx, path(machinearch));
246         }
247         configfile();                   /* put config file into kernel*/
248         options();                      /* make options .h files */
249         makefile();                     /* build Makefile */
250         makeenv();                      /* build env.c */
251         makehints();                    /* build hints.c */
252         headers();                      /* make a lot of .h files */
253         cleanheaders(p);
254         printf("Kernel build directory is %s\n", p);
255         printf("Don't forget to do ``make cleandepend && make depend''\n");
256         exit(0);
257 }
258
259 /*
260  * get_srcdir
261  *      determine the root of the kernel source tree
262  *      and save that in srcdir.
263  */
264 static void
265 get_srcdir(void)
266 {
267         struct stat lg, phy;
268         char *p, *pwd;
269         int i;
270
271         if (realpath("../..", srcdir) == NULL)
272                 err(EXIT_FAILURE, "Unable to find root of source tree");
273         if ((pwd = getenv("PWD")) != NULL && *pwd == '/' &&
274             (pwd = strdup(pwd)) != NULL) {
275                 /* Remove the last two path components. */
276                 for (i = 0; i < 2; i++) {
277                         if ((p = strrchr(pwd, '/')) == NULL) {
278                                 free(pwd);
279                                 return;
280                         }
281                         *p = '\0';
282                 }
283                 if (stat(pwd, &lg) != -1 && stat(srcdir, &phy) != -1 &&
284                     lg.st_dev == phy.st_dev && lg.st_ino == phy.st_ino)
285                         strlcpy(srcdir, pwd, MAXPATHLEN);
286                 free(pwd);
287         }
288 }
289
290 static void
291 usage(void)
292 {
293
294         fprintf(stderr, "usage: config [-CgmpV] [-d destdir] sysname\n");
295         fprintf(stderr, "       config -x kernel\n");
296         exit(EX_USAGE);
297 }
298
299 /*
300  * get_word
301  *      returns EOF on end of file
302  *      NULL on end of line
303  *      pointer to the word otherwise
304  */
305 char *
306 get_word(FILE *fp)
307 {
308         static char line[80];
309         int ch;
310         char *cp;
311         int escaped_nl = 0;
312
313 begin:
314         while ((ch = getc(fp)) != EOF)
315                 if (ch != ' ' && ch != '\t')
316                         break;
317         if (ch == EOF)
318                 return ((char *)EOF);
319         if (ch == '\\'){
320                 escaped_nl = 1;
321                 goto begin;
322         }
323         if (ch == '\n') {
324                 if (escaped_nl){
325                         escaped_nl = 0;
326                         goto begin;
327                 }
328                 else
329                         return (NULL);
330         }
331         cp = line;
332         *cp++ = ch;
333         while ((ch = getc(fp)) != EOF) {
334                 if (isspace(ch))
335                         break;
336                 *cp++ = ch;
337         }
338         *cp = 0;
339         if (ch == EOF)
340                 return ((char *)EOF);
341         (void) ungetc(ch, fp);
342         return (line);
343 }
344
345 /*
346  * get_quoted_word
347  *      like get_word but will accept something in double or single quotes
348  *      (to allow embedded spaces).
349  */
350 char *
351 get_quoted_word(FILE *fp)
352 {
353         static char line[256];
354         int ch;
355         char *cp;
356         int escaped_nl = 0;
357
358 begin:
359         while ((ch = getc(fp)) != EOF)
360                 if (ch != ' ' && ch != '\t')
361                         break;
362         if (ch == EOF)
363                 return ((char *)EOF);
364         if (ch == '\\'){
365                 escaped_nl = 1;
366                 goto begin;
367         }
368         if (ch == '\n') {
369                 if (escaped_nl){
370                         escaped_nl = 0;
371                         goto begin;
372                 }
373                 else
374                         return (NULL);
375         }
376         cp = line;
377         if (ch == '"' || ch == '\'') {
378                 int quote = ch;
379
380                 escaped_nl = 0;
381                 while ((ch = getc(fp)) != EOF) {
382                         if (ch == quote && !escaped_nl)
383                                 break;
384                         if (ch == '\n' && !escaped_nl) {
385                                 *cp = 0;
386                                 printf("config: missing quote reading `%s'\n",
387                                         line);
388                                 exit(2);
389                         }
390                         if (ch == '\\' && !escaped_nl) {
391                                 escaped_nl = 1;
392                                 continue;
393                         }
394                         if (ch != quote && escaped_nl)
395                                 *cp++ = '\\';
396                         *cp++ = ch;
397                         escaped_nl = 0;
398                 }
399         } else {
400                 *cp++ = ch;
401                 while ((ch = getc(fp)) != EOF) {
402                         if (isspace(ch))
403                                 break;
404                         *cp++ = ch;
405                 }
406                 if (ch != EOF)
407                         (void) ungetc(ch, fp);
408         }
409         *cp = 0;
410         if (ch == EOF)
411                 return ((char *)EOF);
412         return (line);
413 }
414
415 /*
416  * prepend the path to a filename
417  */
418 char *
419 path(const char *file)
420 {
421         char *cp = NULL;
422
423         if (file)
424                 asprintf(&cp, "%s/%s", destdir, file);
425         else
426                 cp = strdup(destdir);
427         return (cp);
428 }
429
430 /*
431  * Generate configuration file based on actual settings. With this mode, user
432  * will be able to obtain and build conifguration file with one command.
433  */
434 static void
435 configfile_dynamic(struct sbuf *sb)
436 {
437         struct cputype *cput;
438         struct device *d;
439         struct opt *ol;
440         char *lend;
441         unsigned int i;
442
443         asprintf(&lend, "\\n\\\n");
444         assert(lend != NULL);
445         sbuf_printf(sb, "options\t%s%s", OPT_AUTOGEN, lend);
446         sbuf_printf(sb, "ident\t%s%s", ident, lend);
447         sbuf_printf(sb, "machine\t%s%s", machinename, lend);
448         SLIST_FOREACH(cput, &cputype, cpu_next)
449                 sbuf_printf(sb, "cpu\t%s%s", cput->cpu_name, lend);
450         SLIST_FOREACH(ol, &mkopt, op_next)
451                 sbuf_printf(sb, "makeoptions\t%s=%s%s", ol->op_name,
452                     ol->op_value, lend);
453         SLIST_FOREACH(ol, &opt, op_next) {
454                 if (strncmp(ol->op_name, "DEV_", 4) == 0)
455                         continue;
456                 sbuf_printf(sb, "options\t%s", ol->op_name);
457                 if (ol->op_value != NULL) {
458                         sbuf_putc(sb, '=');
459                         for (i = 0; i < strlen(ol->op_value); i++) {
460                                 if (ol->op_value[i] == '"')
461                                         sbuf_printf(sb, "\\%c",
462                                             ol->op_value[i]);
463                                 else
464                                         sbuf_printf(sb, "%c",
465                                             ol->op_value[i]);
466                         }
467                         sbuf_printf(sb, "%s", lend);
468                 } else {
469                         sbuf_printf(sb, "%s", lend);
470                 }
471         }
472         /*
473          * Mark this file as containing everything we need.
474          */
475         STAILQ_FOREACH(d, &dtab, d_next)
476                 sbuf_printf(sb, "device\t%s%s", d->d_name, lend);
477         free(lend);
478 }
479
480 /*
481  * Generate file from the configuration files.
482  */
483 static void
484 configfile_filebased(struct sbuf *sb)
485 {
486         FILE *cff;
487         struct cfgfile *cf;
488         int i;
489
490         /*
491          * Try to read all configuration files. Since those will be present as
492          * C string in the macro, we have to slash their ends then the line
493          * wraps.
494          */
495         STAILQ_FOREACH(cf, &cfgfiles, cfg_next) {
496                 cff = fopen(cf->cfg_path, "r");
497                 if (cff == NULL) {
498                         warn("Couldn't open file %s", cf->cfg_path);
499                         continue;
500                 }
501                 while ((i = getc(cff)) != EOF) {
502                         if (i == '\n')
503                                 sbuf_printf(sb, "\\n\\\n");
504                         else if (i == '"' || i == '\'')
505                                 sbuf_printf(sb, "\\%c", i);
506                         else
507                                 sbuf_putc(sb, i);
508                 }
509                 fclose(cff);
510         }
511 }
512
513 static void
514 configfile(void)
515 {
516         FILE *fo;
517         struct sbuf *sb;
518         char *p;
519
520         /* Add main configuration file to the list of files to be included */
521         cfgfile_add(PREFIX);
522         p = path("config.c.new");
523         fo = fopen(p, "w");
524         if (!fo)
525                 err(2, "%s", p);
526         sb = sbuf_new(NULL, NULL, 2048, SBUF_AUTOEXTEND);
527         assert(sb != NULL);
528         sbuf_clear(sb);
529         if (filebased) {
530                 /* Is needed, can be used for backward compatibility. */
531                 configfile_filebased(sb);
532         } else {
533                 configfile_dynamic(sb);
534         }
535         sbuf_finish(sb);
536         /* 
537          * We print first part of the template, replace our tag with
538          * configuration files content and later continue writing our
539          * template.
540          */
541         p = strstr(kernconfstr, KERNCONFTAG);
542         if (p == NULL)
543                 errx(EXIT_FAILURE, "Something went terribly wrong!");
544         *p = '\0';
545         fprintf(fo, "%s", kernconfstr);
546         fprintf(fo, "%s", sbuf_data(sb));
547         p += strlen(KERNCONFTAG);
548         fprintf(fo, "%s", p);
549         sbuf_delete(sb);
550         fclose(fo);
551         moveifchanged(path("config.c.new"), path("config.c"));
552         cfgfile_removeall();
553 }
554
555 /*
556  * moveifchanged --
557  *      compare two files; rename if changed.
558  */
559 void
560 moveifchanged(const char *from_name, const char *to_name)
561 {
562         char *p, *q;
563         int changed;
564         size_t tsize;
565         struct stat from_sb, to_sb;
566         int from_fd, to_fd;
567
568         changed = 0;
569
570         if ((from_fd = open(from_name, O_RDONLY)) < 0)
571                 err(EX_OSERR, "moveifchanged open(%s)", from_name);
572
573         if ((to_fd = open(to_name, O_RDONLY)) < 0)
574                 changed++;
575
576         if (!changed && fstat(from_fd, &from_sb) < 0)
577                 err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
578
579         if (!changed && fstat(to_fd, &to_sb) < 0)
580                 err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
581
582         if (!changed && from_sb.st_size != to_sb.st_size)
583                 changed++;
584
585         tsize = (size_t)from_sb.st_size;
586
587         if (!changed) {
588                 p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
589                 if (p == MAP_FAILED)
590                         err(EX_OSERR, "mmap %s", from_name);
591                 q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
592                 if (q == MAP_FAILED)
593                         err(EX_OSERR, "mmap %s", to_name);
594
595                 changed = memcmp(p, q, tsize);
596                 munmap(p, tsize);
597                 munmap(q, tsize);
598         }
599         if (changed) {
600                 if (rename(from_name, to_name) < 0)
601                         err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
602         } else {
603                 if (unlink(from_name) < 0)
604                         err(EX_OSERR, "unlink(%s)", from_name);
605         }
606 }
607
608 static void
609 cleanheaders(char *p)
610 {
611         DIR *dirp;
612         struct dirent *dp;
613         struct file_list *fl;
614         struct hdr_list *hl;
615         size_t len;
616
617         remember("y.tab.h");
618         remember("setdefs.h");
619         STAILQ_FOREACH(fl, &ftab, f_next)
620                 remember(fl->f_fn);
621
622         /*
623          * Scan the build directory and clean out stuff that looks like
624          * it might have been a leftover NFOO header, etc.
625          */
626         if ((dirp = opendir(p)) == NULL)
627                 err(EX_OSERR, "opendir %s", p);
628         while ((dp = readdir(dirp)) != NULL) {
629                 len = strlen(dp->d_name);
630                 /* Skip non-headers */
631                 if (len < 2 || dp->d_name[len - 2] != '.' ||
632                     dp->d_name[len - 1] != 'h')
633                         continue;
634                 /* Skip special stuff, eg: bus_if.h, but check opt_*.h */
635                 if (strchr(dp->d_name, '_') &&
636                     strncmp(dp->d_name, "opt_", 4) != 0)
637                         continue;
638                 /* Check if it is a target file */
639                 for (hl = htab; hl != NULL; hl = hl->h_next) {
640                         if (eq(dp->d_name, hl->h_name)) {
641                                 break;
642                         }
643                 }
644                 if (hl)
645                         continue;
646                 printf("Removing stale header: %s\n", dp->d_name);
647                 if (unlink(path(dp->d_name)) == -1)
648                         warn("unlink %s", dp->d_name);
649         }
650         (void)closedir(dirp);
651 }
652
653 void
654 remember(const char *file)
655 {
656         char *s;
657         struct hdr_list *hl;
658
659         if ((s = strrchr(file, '/')) != NULL)
660                 s = ns(s + 1);
661         else
662                 s = ns(file);
663
664         if (index(s, '_') && strncmp(s, "opt_", 4) != 0) {
665                 free(s);
666                 return;
667         }
668         for (hl = htab; hl != NULL; hl = hl->h_next) {
669                 if (eq(s, hl->h_name)) {
670                         free(s);
671                         return;
672                 }
673         }
674         hl = calloc(1, sizeof(*hl));
675         if (hl == NULL)
676                 err(EXIT_FAILURE, "calloc");
677         hl->h_name = s;
678         hl->h_next = htab;
679         htab = hl;
680 }
681
682 /*
683  * This one is quick hack. Will be probably moved to elf(3) interface.
684  * It takes kernel configuration file name, passes it as an argument to
685  * elfdump -a, which output is parsed by some UNIX tools...
686  */
687 static void
688 kernconfdump(const char *file)
689 {
690         struct stat st;
691         FILE *fp, *pp;
692         int error, len, osz, r;
693         unsigned int i, off, size, t1, t2, align;
694         char *cmd, *o;
695
696         r = open(file, O_RDONLY);
697         if (r == -1)
698                 err(EXIT_FAILURE, "Couldn't open file '%s'", file);
699         error = fstat(r, &st);
700         if (error == -1)
701                 err(EXIT_FAILURE, "fstat() failed");
702         if (S_ISDIR(st.st_mode))
703                 errx(EXIT_FAILURE, "'%s' is a directory", file);
704         fp = fdopen(r, "r");
705         if (fp == NULL)
706                 err(EXIT_FAILURE, "fdopen() failed");
707         osz = 1024;
708         o = calloc(1, osz);
709         if (o == NULL)
710                 err(EXIT_FAILURE, "Couldn't allocate memory");
711         /* ELF note section header. */
712         asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 8 kern_conf"
713             "| tail -5 | cut -d ' ' -f 2 | paste - - - - -", file);
714         if (cmd == NULL)
715                 errx(EXIT_FAILURE, "asprintf() failed");
716         pp = popen(cmd, "r");
717         if (pp == NULL)
718                 errx(EXIT_FAILURE, "popen() failed");
719         free(cmd);
720         len = fread(o, osz, 1, pp);
721         pclose(pp);
722         r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align);
723         free(o);
724         if (r != 5)
725                 errx(EXIT_FAILURE, "File %s doesn't contain configuration "
726                     "file. Either unsupported, or not compiled with "
727                     "INCLUDE_CONFIG_FILE", file);
728         r = fseek(fp, off, SEEK_CUR);
729         if (r != 0)
730                 err(EXIT_FAILURE, "fseek() failed");
731         for (i = 0; i < size; i++) {
732                 r = fgetc(fp);
733                 if (r == EOF)
734                         break;
735                 /* 
736                  * If '\0' is present in the middle of the configuration
737                  * string, this means something very weird is happening.
738                  * Make such case very visible.  However, some architectures
739                  * pad the length of the section with NULs to a multiple of
740                  * sh_addralign, allow a NUL in that part of the section.
741                  */
742                 if (r == '\0' && (size - i) < align)
743                         break;
744                 assert(r != '\0' && ("Char present in the configuration "
745                     "string mustn't be equal to 0"));
746                 fputc(r, stdout);
747         }
748         fclose(fp);
749 }
750
751 static void 
752 badversion(int versreq)
753 {
754         fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
755         fprintf(stderr, "config version = %d, ", CONFIGVERS);
756         fprintf(stderr, "version required = %d\n\n", versreq);
757         fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
758         fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
759         fprintf(stderr, "before trying this again.\n\n");
760         fprintf(stderr, "If running the new config fails check your config\n");
761         fprintf(stderr, "file against the GENERIC or LINT config files for\n");
762         fprintf(stderr, "changes in config syntax, or option/device naming\n");
763         fprintf(stderr, "conventions\n\n");
764         exit(1);
765 }
766
767 static void
768 checkversion(void)
769 {
770         FILE *ifp;
771         char line[BUFSIZ];
772         int versreq;
773
774         ifp = open_makefile_template();
775         while (fgets(line, BUFSIZ, ifp) != 0) {
776                 if (*line != '%')
777                         continue;
778                 if (strncmp(line, "%VERSREQ=", 9) != 0)
779                         continue;
780                 versreq = atoi(line + 9);
781                 if (MAJOR_VERS(versreq) == MAJOR_VERS(CONFIGVERS) &&
782                     versreq <= CONFIGVERS)
783                         continue;
784                 badversion(versreq);
785         }
786         fclose(ifp);
787 }