From nobody@FreeBSD.org  Fri Aug  5 12:39:24 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id EA34016A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  5 Aug 2005 12:39:24 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id AE50A43D46
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  5 Aug 2005 12:39:24 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j75CdO4s040210
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 5 Aug 2005 12:39:24 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j75CdOx5040209;
	Fri, 5 Aug 2005 12:39:24 GMT
	(envelope-from nobody)
Message-Id: <200508051239.j75CdOx5040209@www.freebsd.org>
Date: Fri, 5 Aug 2005 12:39:24 GMT
From: Kostik Belousov <kostikbel@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
X-Send-Pr-Version: www-2.3

>Number:         84581
>Category:       conf
>Synopsis:       [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 05 12:40:13 GMT 2005
>Closed-Date:    Fri Mar 16 07:42:55 GMT 2007
>Last-Modified:  Fri Mar 16 07:42:55 GMT 2007
>Originator:     Kostik Belousov
>Release:        7-CURRENT, 5-STABLE
>Organization:
-
>Environment:
FreeBSD deviant.zoral.local 5.4-STABLE FreeBSD 5.4-STABLE #62: Thu Jul 21 18:01:51 EEST 2005 root@deviant.zoral.local:/usr/obj/usr/src/sys/DEVIANT  i386
>Description:
The site-specific FreeBSD kernel config files are placed inside the
tree in the <src>/sys/ARCH/conf directory. This is inconvinient since
configs are not controlled by the cvs. If someone do rm -rf <src> &&
cvs get src, configs have to be backed up before rm and restored after
get. Moreover, it makes hard to deal with read-only nfs export of
sources to build machines.

I propose a patch for config(8) and Makefile.inc1 that allows to keep
configs under /etc, where local configuration supposed to be stored.

Patch allows to take configs not only from sys/ARCH/conf but also from
/etc/SYSTEM.kernconf, where SYSTEM is system name supplied to
config(8).

Patch applicable to both 7-CURRENT and 5-STABLE.

>How-To-Repeat:
      
>Fix:
Index: Makefile.inc1
===================================================================
RCS file: /usr/local/arch/ncvs/src/Makefile.inc1,v
retrieving revision 1.508
diff -u -r1.508 Makefile.inc1
--- Makefile.inc1	3 Aug 2005 20:27:06 -0000	1.508
+++ Makefile.inc1	5 Aug 2005 11:02:25 -0000
@@ -585,7 +585,7 @@
 BUILDKERNELS=
 INSTALLKERNEL=
 .for _kernel in ${KERNCONF}
-.if exists(${KERNCONFDIR}/${_kernel})
+.if exists(${KERNCONFDIR}/${_kernel}) || exists(/etc/${_kernel}.kernconf)
 BUILDKERNELS+=	${_kernel}
 .if empty(INSTALLKERNEL)
 INSTALLKERNEL= ${_kernel}
@@ -624,7 +624,7 @@
 	cd ${KRNLCONFDIR}; \
 		PATH=${TMPPATH} \
 		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
-			${KERNCONFDIR}/${_kernel}
+			${_kernel}
 .endif
 .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
 	@echo
Index: usr.sbin/config/config.8
===================================================================
RCS file: /usr/local/arch/ncvs/src/usr.sbin/config/config.8,v
retrieving revision 1.43
diff -u -r1.43 config.8
--- usr.sbin/config/config.8	18 Jan 2005 20:02:33 -0000	1.43
+++ usr.sbin/config/config.8	5 Aug 2005 11:04:43 -0000
@@ -97,6 +97,9 @@
 Specify the name of the system configuration file
 containing device specifications, configuration options
 and other system parameters for one system configuration.
+If the SYSTEM_NAME does not contain '/' and the file SYSTEM_NAME
+does not exist in the current directory,
+the path /etc/SYSTEM_NAME.kernconf will be tried as fallback.
 .El
 .Pp
 The
Index: usr.sbin/config/main.c
===================================================================
RCS file: /usr/local/arch/ncvs/src/usr.sbin/config/main.c,v
retrieving revision 1.64
diff -u -r1.64 main.c
--- usr.sbin/config/main.c	22 Apr 2005 17:42:50 -0000	1.64
+++ usr.sbin/config/main.c	5 Aug 2005 11:04:45 -0000
@@ -66,6 +66,7 @@
 #define	CDIR	"../compile/"
 
 char *	PREFIX;
+char *  config_file_name;
 char 	destdir[MAXPATHLEN];
 char 	srcdir[MAXPATHLEN];
 
@@ -119,8 +120,31 @@
 	if (argc != 1)
 		usage();
 
-	if (freopen(PREFIX = *argv, "r", stdin) == NULL)
-		err(2, "%s", PREFIX);
+	PREFIX = *argv;
+	config_file_name = *argv;
+	yyfile = config_file_name;
+	if (freopen(config_file_name, "r", stdin) == NULL) {
+		if (strchr(config_file_name, '/') == NULL) {
+			static const char prefix[] = "/etc/";
+			static const char suffix[] = ".kernconf";
+			char *etcname = malloc(sizeof(prefix) +
+					       sizeof(suffix) + strlen(config_file_name) - 1);
+			if (etcname == NULL)
+				err(2, NULL);
+			strcpy(etcname, prefix);
+			strcat(etcname, config_file_name);
+			strcat(etcname, suffix);
+
+			if (freopen(etcname, "r", stdin) == NULL)
+				err(2, "%s", etcname);
+			else {
+				yyfile = etcname;
+				config_file_name = etcname;
+			}
+		}
+		else
+			err(2, "%s", config_file_name);
+	}
 
 	if (*destdir != '\0') {
 		len = strlen(destdir);
@@ -144,7 +168,6 @@
 	STAILQ_INIT(&fntab);
 	SLIST_INIT(&cputype);
 	STAILQ_INIT(&ftab);
-	yyfile = *argv;
 	if (yyparse())
 		exit(3);
 	if (machinename == NULL) {
@@ -338,9 +361,9 @@
 	char *p;
 	int i;
 	
-	fi = fopen(PREFIX, "r");
+	fi = fopen(config_file_name, "r");
 	if (!fi)
-		err(2, "%s", PREFIX);
+		err(2, "%s", config_file_name);
 	fo = fopen(p=path("config.c.new"), "w");
 	if (!fo)
 		err(2, "%s", p);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Tue Feb 20 14:50:36 UTC 2007 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84581 

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: bug-followup@FreeBSD.org, kostikbel@gmail.com, spam@rm-rf.kiev.ua
Cc:  
Subject: Re: conf/84581: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
Date: Thu, 22 Feb 2007 00:53:10 +0200

 Hi
 
 I found much easier to define KERNCONF and KERNCONFDIR
 in /etc/make.conf(/etc/src.conf)
 
 
 --
 Adios

From: Kostik Belousov <kostikbel@gmail.com>
To: Alex Kozlov <spam@rm-rf.kiev.ua>
Cc: bug-followup@freebsd.org
Subject: Re: conf/84581: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
Date: Thu, 22 Feb 2007 11:42:26 +0200

 --JVTRtevMO87SusWP
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Thu, Feb 22, 2007 at 12:53:10AM +0200, Alex Kozlov wrote:
 > Hi
 >=20
 > I found much easier to define KERNCONF and KERNCONFDIR
 > in /etc/make.conf(/etc/src.conf)
 >=20
 
 Heh, it ought to be closed/withdrawn long time ago. But I do not object
 if the change would be committed after testing it on modern systems.
 
 BTW, would redefinition of KERNCONFDIR work ? Basically, is DEFAULTS still
 found while KERNCONFDIR points, for instance, into /etc ?
 
 --JVTRtevMO87SusWP
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (FreeBSD)
 
 iD8DBQFF3WWBC3+MBN1Mb4gRAvADAJwPs9tlVsvDVnnaXXHT5SnRU/0NFgCeIiNC
 /Fz8m3XPgwNey93AUezMSxQ=
 =Ch59
 -----END PGP SIGNATURE-----
 
 --JVTRtevMO87SusWP--

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: Kostik Belousov <kostikbel@gmail.com>, bug-followup@freebsd.org,
	spam@rm-rf.kiev.ua
Cc:  
Subject: Re: conf/84581: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
Date: Thu, 22 Feb 2007 16:13:50 +0200

 On Thu, Feb 22, 2007 at 11:42:26AM +0200, Kostik Belousov wrote:
 > On Thu, Feb 22, 2007 at 12:53:10AM +0200, Alex Kozlov wrote:
 > > 
 > > I found much easier to define KERNCONF and KERNCONFDIR
 > > in /etc/make.conf(/etc/src.conf)
 > > 
 > 
 > Heh, it ought to be closed/withdrawn long time ago. But I do not object
 > if the change would be committed after testing it on modern systems.
 > 
 > BTW, would redefinition of KERNCONFDIR work ? Basically, is DEFAULTS still
 > found while KERNCONFDIR points, for instance, into /etc ?
 After little patch. 
 If ${KERNCONFDIR}/${_kernel} not found, check ${KRNLCONFDIR}/${_kernel}:
 
 --- /usr/src/Makefile.inc1
 +++ /usr/src/Makefile.inc1.new
 @@ -631,7 +631,7 @@
  BUILDKERNELS=
  INSTALLKERNEL=
  .for _kernel in ${KERNCONF}
 -.if exists(${KERNCONFDIR}/${_kernel})
 +.if exists(${KERNCONFDIR}/${_kernel}) || exists(${KRNLCONFDIR}/${_kernel})
  BUILDKERNELS+= ${_kernel}
  .if empty(INSTALLKERNEL)
  INSTALLKERNEL= ${_kernel}
 @@ -667,10 +667,17 @@
         @echo "--------------------------------------------------------------"
         @echo ">>> stage 1: configuring the kernel"
         @echo "--------------------------------------------------------------"
 +.if exists(${KERNCONFDIR}/${_kernel})
         cd ${KRNLCONFDIR}; \
                 PATH=${TMPPATH} \
                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
                         ${KERNCONFDIR}/${_kernel}
 +.elif exists(${KRNLCONFDIR}/${_kernel})
 +       cd ${KRNLCONFDIR}; \
 +               PATH=${TMPPATH} \
 +               config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
 +                       ${KRNLCONFDIR}/${_kernel}
 +.endif
  .endif
  .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
         @echo
 
 
 $echo 'KERNCONF?=DE.KRNL GENERIC' >> /etc/make.conf 
 $echo 'KERNCONFDIR?=/etc/site/' >> /etc/make.conf 
 #cd /usr/src; make buildkernel 
 
 DE.KRNL config will be get from /etc/site/DE.KRNL and GENERIC config
 from /usr/src/sys/i386/conf/GENERIC
 
 
 --
 Adios

From: Kostik Belousov <kostikbel@gmail.com>
To: Alex Kozlov <spam@rm-rf.kiev.ua>
Cc: bug-followup@freebsd.org
Subject: Re: conf/84581: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
Date: Thu, 22 Feb 2007 16:50:19 +0200

 --jFijuCULRDbBA23d
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Thu, Feb 22, 2007 at 04:13:50PM +0200, Alex Kozlov wrote:
 > > BTW, would redefinition of KERNCONFDIR work ? Basically, is DEFAULTS st=
 ill
 > > found while KERNCONFDIR points, for instance, into /etc ?
 > After little patch.=20
 > If ${KERNCONFDIR}/${_kernel} not found, check ${KRNLCONFDIR}/${_kernel}:
 >=20
 DEFAULT is sourced from the current working directory, but is located in
 /sys/<arch>/conf.
 
 --jFijuCULRDbBA23d
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (FreeBSD)
 
 iD8DBQFF3a2qC3+MBN1Mb4gRAqolAJ9yAdAk03rn00pkI4ALTiQqgpke6ACgp/2q
 JtHpT0LRUYKChQAkbI+j18Q=
 =V/TR
 -----END PGP SIGNATURE-----
 
 --jFijuCULRDbBA23d--

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: Kostik Belousov <kostikbel@gmail.com>, bug-followup@freebsd.org,
	spam@rm-rf.kiev.ua
Cc:  
Subject: Re: conf/84581: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
Date: Thu, 22 Feb 2007 18:16:56 +0200

 On Thu, Feb 22, 2007 at 04:50:19PM +0200, Kostik Belousov wrote:
 > On Thu, Feb 22, 2007 at 04:13:50PM +0200, Alex Kozlov wrote:
 > > > BTW, would redefinition of KERNCONFDIR work ? Basically, is DEFAULTS still
 > > > found while KERNCONFDIR points, for instance, into /etc ?
 > > After little patch. 
 > > If ${KERNCONFDIR}/${_kernel} not found, check ${KRNLCONFDIR}/${_kernel}:
 > > 
 > DEFAULT is sourced from the current working directory, but is located in
 > /sys/<arch>/conf.
 Sorry. I misunderstand you.
 No. If KERNCONFDIR redefined, DEFAULTS can't be found. 
 I just include isa, npx and other options in my custom config.
 Also posible to copy DEFAULTS to KERNCONFDIR
 Still, more elegant solution would be nice.
 
 
 --
 Adios

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: Kostik Belousov <kostikbel@gmail.com>, bug-followup@freebsd.org,
	spam@rm-rf.kiev.ua
Cc:  
Subject: Re: conf/84581: [patch] Teach config(8) to look for kernel configuration in /etc/SYSTEM.kernconf
Date: Thu, 22 Feb 2007 18:30:53 +0200

 Hi, Kostik
 
 Sorry again. Before invoke config, make change dir to KRNLCONFDIR.
 KRNLCONFDIR defined as ${KERNSRCDIR}/${TARGET}/conf 
 Therefore no problem with DEFAULTS
 
 
 --
 Adios
State-Changed-From-To: open->closed 
State-Changed-By: remko 
State-Changed-When: Fri Mar 16 07:42:53 UTC 2007 
State-Changed-Why:  
OK by using KERNCONFDIR you can specify an alternate location for your 
kernel configurations. If you copy the entire skeleton over there you 
have unmodified defaults etc there. People building custom sources most 
often know how CVS works and know that rm -rf src will also remove their 
custom kernel configuration. I wont be continueing on this thus to 
reflect that close the ticket. I am sorry that this took some time to 
digest in my head ;) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84581 
>Unformatted:
