From owner-freebsd-hackers Sat Oct 13 8:47:48 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from cs.huji.ac.il (cs.huji.ac.il [132.65.16.10]) by hub.freebsd.org (Postfix) with ESMTP id 6100F37B411 for ; Sat, 13 Oct 2001 08:43:41 -0700 (PDT) Received: from narn.cs.huji.ac.il ([132.65.80.43] ident=exim) by cs.huji.ac.il with esmtp (Exim 3.32 #1) id 15sQwt-00022l-00 for freebsd-hackers@freebsd.org; Sat, 13 Oct 2001 17:43:39 +0200 Received: from vadik by narn.cs.huji.ac.il with local (Exim 3.32 #1) id 15sQwt-0005XC-00 for freebsd-hackers@freebsd.org; Sat, 13 Oct 2001 17:43:39 +0200 Date: Sat, 13 Oct 2001 17:43:39 +0200 From: Vadim Vygonets To: freebsd-hackers@freebsd.org Subject: loader.conf conditional assignment Message-ID: <20011013174339.A21230@cs.huji.ac.il> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="fUYQa+Pmc3FrFX/N" Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Operating-System: BSD/OS narn.cs.huji.ac.il 4.2 i386 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: inline We are working on integration of network-booted FreeBSD system to our envoronment. Naturally, different machines need different kernels, so we pass the kernel paramater in DHCP response. However, it gets overwritten in /boot/defaults/loader.conf. We decided that commenting out the assignment of 'kernel' and 'kernel_options' is not what we want, because we want both to use the default value and to be able to override it via DHCP. After taking some time to learn Forth (interesting language, I must say) and a false start (involving saving environment variables (names and values) in a linked list and restoring them after the assignment), I decided to use the Makefile syntax of ?= to set an environment variable if it's not set yet, so it will be possible to say: kernel?="/kernel" In this case, if kernel is set via DHCP, the value is not changed, but if it's not, it becomes "/kernel". Attached is the patch for /boot/support.4th against the version in FreeBSD 4.4. Vadik. -- Bell Labs Unix -- Reach out and grep someone. --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="support.4th.diff" --- ../../4.4/boot/support.4th Thu Aug 9 08:52:20 2001 +++ support.4th Thu Oct 11 20:11:29 2001 @@ -190,6 +190,9 @@ string name_buffer string value_buffer +variable assignment_op +char = constant regular_assignment +char ? constant notdef_assignment \ File data temporary storage @@ -331,6 +334,10 @@ line_pointer c@ [char] = = ; +: question_mark? + line_pointer c@ [char] ? = +; + : comment? line_pointer c@ [char] # = ; @@ -464,8 +471,16 @@ ['] white_space_3 to parsing_function ; +: question_mark + notdef_assignment assignment_op ! + skip_character + assignment_sign? if ['] assignment_sign to parsing_function exit then + syntax_error throw +; + : white_space_2 eat_space + question_mark? if ['] question_mark to parsing_function exit then assignment_sign? if ['] assignment_sign to parsing_function exit then syntax_error throw ; @@ -554,6 +569,10 @@ module_loaderror_suffix suffix_type? ; +: notdef_assignment? + assignment_op @ notdef_assignment = +; + : set_conf_files conf_files .addr @ ?dup if free-memory @@ -717,6 +736,14 @@ then ; +: set_environment_variable_if_notdef + name_buffer .addr @ name_buffer .len @ getenv -1 = if + set_environment_variable + else + drop + then +; + : set_verbose yes_value? to verbose? ; @@ -754,6 +781,7 @@ module_beforeload? if set_module_beforeload exit then module_afterload? if set_module_afterload exit then module_loaderror? if set_module_loaderror exit then + notdef_assignment? if set_environment_variable_if_notdef exit then set_environment_variable ; @@ -775,6 +803,7 @@ 0 name_buffer .len ! 0 value_buffer .addr ! 0 value_buffer .len ! + regular_assignment assignment_op ! ; \ Higher level file processing --fUYQa+Pmc3FrFX/N-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message