Date: Wed, 5 Dec 2012 21:23:03 -0800 From: Garrett Cooper <yanegomi@gmail.com> To: freebsd-toolchain@freebsd.org Subject: [RFC] teach config(8) about KERNCONFDIR Message-ID: <CAGH67wSxUSdGSwyHx-TV=1iP4UgpCm8SN%2BHrLym_pAhsXbKk_Q@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
(Sorry in advance for GMail mangling). I recently moved all of my svn trees to git and in order to ensure that my trees are in as pristine a state as possible I've started setting KERNCONFDIR=/root in /etc/src.conf and I specify KERNCONF?= <foo> <foo>-DEBUG. This works pretty well in a standard setup (when files are located in /sys/<arch>/conf, are standalone, etc). In order to eliminate duplication, I wrote <foo>-DEBUG to include <foo> and augment it a bit (enable WITNESS, INVARIANTS, etc). However, I discovered that if I do this, config fails to find the file because it only knows how to find 1) absolute paths, 2) relative paths to the obj dir, and 3) as a last ditch effort it tries to use ../../conf/ (/sys/conf I believe for the generic KERNCONF directory). I added the patch below to teach config(8) about KERNCONFDIR for my own local use (and I think fixed a subtle bug with asprintf and free usage), but the support seems hacky. Another alternative (after doing a bit of research) that looks better is NetBSD's concept of prefix paths: prefix [path] If path is given, it pushes a new prefix for include and cinclude. prefix statements act like a stack, and an empty path argument has the latest prefix popped out. The path argument is either absolute or rela- tive to the current defined prefix, which defaults to the top of ther kernel source tree. This sounds like a more generic way to resolve the issue when combined with defparam as described in config(5) [1]. I was wondering if anyone would be interested in this support or not (assuming that porting over the feature is trivial enough to do). If so I'll look at just porting over the support for defparam and prefix directives and will submit a PR for it if successful. If no one's interested in it, I can just hack my src.conf to use /root or autoprefix the path to the ${KERNCONF} and be done with it. Thanks! -Garrett PS Please CC me when replying as I'm not currently subscribed to toolchain@. 1. http://netbsd.gw.com/cgi-bin/man-cgi?config+5+NetBSD-current $ git diff usr.sbin/config/ diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l index 81f820f..2eba2b8 100644 --- a/usr.sbin/config/lang.l +++ b/usr.sbin/config/lang.l @@ -34,6 +34,8 @@ #include <assert.h> #include <ctype.h> #include <err.h> +#include <errno.h> +#include <stdlib.h> #include <string.h> #include "y.tab.h" #include "config.h" @@ -255,22 +257,31 @@ include(const char *fname, int ateof) { FILE *fp; struct incl *in; - char *fnamebuf; + char *fnamebuf, *kernconfdir; fnamebuf = NULL; fp = fopen(fname, "r"); if (fp == NULL && fname[0] != '.' && fname[0] != '/') { asprintf(&fnamebuf, "../../conf/%s", fname); - if (fnamebuf != NULL) { + if (fnamebuf != NULL) fp = fopen(fnamebuf, "r"); - free(fnamebuf); + } + /* If the first attempt failed, try again in ${KERNCONFDIR}. */ + if (fp == NULL) { + kernconfdir = getenv("KERNCONFDIR"); + if (kernconfdir != NULL) { + asprintf(&fnamebuf, "%s/%s", kernconfdir, fname); + if (fnamebuf != NULL) + fp = fopen(fnamebuf, "r"); } } if (fp == NULL) { + free(fnamebuf); yyerror("cannot open included file"); return (-1); } cfgfile_add(fnamebuf == NULL ? fname : fnamebuf); + free(fnamebuf); in = malloc(sizeof(*in)); assert(in != NULL); in->in_prev = inclp;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wSxUSdGSwyHx-TV=1iP4UgpCm8SN%2BHrLym_pAhsXbKk_Q>