Date: Sat, 13 Oct 2001 17:43:39 +0200 From: Vadim Vygonets <vadik-hackers@freebsd.vygo.net> To: freebsd-hackers@freebsd.org Subject: loader.conf conditional assignment Message-ID: <20011013174339.A21230@cs.huji.ac.il>
next in thread | raw e-mail | index | archive | help
--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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011013174339.A21230>