From owner-freebsd-toolchain@FreeBSD.ORG Thu Dec 6 05:23:05 2012 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 581F913D5 for ; Thu, 6 Dec 2012 05:23:05 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-oa0-f54.google.com (mail-oa0-f54.google.com [209.85.219.54]) by mx1.freebsd.org (Postfix) with ESMTP id 197548FC0C for ; Thu, 6 Dec 2012 05:23:04 +0000 (UTC) Received: by mail-oa0-f54.google.com with SMTP id n9so7693474oag.13 for ; Wed, 05 Dec 2012 21:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=1/VMsiKjxF8xNMukxfqetWjj8+fixPmwGBdGaXA6GdU=; b=xgA8we4kt1plfxsOi5k67oewn/ob06YL6KGCLd0+BY/PWZg4JczY3LRpLr0FxuSSWY Wudvqc1W4fDSrx2M/I9/gmKg2LxynkVI0ukLBUNy8wtrrVhg595XrctXGHwtD+6QUq3w NkdcVSnQFENvnLb5Bes3g1Z09tVWZhEMU7HNcCcDEwZsTleZI79qs9C2jrf0LqZdSsYQ QtkXau6wmo1Eoq8NilmumbNP0mnf5ppz8qnSjhDY+sN0jxHMdNlxd0ErXqwrcMvqnew1 u1z0BJT7bKBZJayG/6b+P9fvQht2yYFDJbMuzQANMyJg3c39kBgnky2XFzRXfNOjZyA7 GAfA== MIME-Version: 1.0 Received: by 10.60.172.178 with SMTP id bd18mr157320oec.133.1354771384284; Wed, 05 Dec 2012 21:23:04 -0800 (PST) Received: by 10.76.143.33 with HTTP; Wed, 5 Dec 2012 21:23:03 -0800 (PST) Date: Wed, 5 Dec 2012 21:23:03 -0800 Message-ID: Subject: [RFC] teach config(8) about KERNCONFDIR From: Garrett Cooper To: freebsd-toolchain@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Dec 2012 05:23:05 -0000 (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?= -DEBUG. This works pretty well in a standard setup (when files are located in /sys//conf, are standalone, etc). In order to eliminate duplication, I wrote -DEBUG to include 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 #include #include +#include +#include #include #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;