reload rc.conf during boot process

Giorgos Keramidas keramida at ceid.upatras.gr
Tue Sep 21 02:37:20 PDT 2004


On 2004-09-21 00:26, Markie <mark.cullen at dsl.pipex.com> wrote:
> Is it possible to do this somehow?
>
> I was trying my hand out at C and made a cool little menu for myself. It
> looks for files in /etc/ which are named rc.conf.xxxxx and lists them in
> the menu. Then, when you select one on boot, it copies the selected
> configuration file to rc.conf. I put my program in... the rc.d mount
> script, so that the disk is mounted writeable at the time and my C program
> is able to issue cp (bad way I know) to replace rc.conf. After running my
> program in the rc.d mount script I then did a
>
> . /etc/rc.conf
>
> but rc.conf doesn't get reloaded. The file is being copied over, as when I
> reboot it starts using the copied over configuration. I am not sure if .
> /etc/rc.conf is supposed to load a file in? I just saw it in some other
> script and assumed that's what it was doing.

The /etc/rc script is a ``driver script'' that loads rc.conf before teh
mount script has a chance to run.  Even if you reload rc.conf in the
mountd script this cannot affect the parent process that runs /etc/rc.

I believe a good way to do this would be to add a special script in
/etc/rc.d that depends on mountcritlocal that can give you the rc.conf
selection menu and then hack /etc/rc to reload rc.conf if this special
script runs and does indeed change `/etc/rc.conf'.

For instance, if you called your special rc.d script that presents the
rc.conf selection menu ``selectcf'' and saved it in /etc/rc.d, then you
could use something like this in /etc/rc to make sure it rereads rc.conf
if changes are made to rc.conf:

% Index: rc
% ===================================================================
% RCS file: /home/ncvs/src/etc/rc,v
% retrieving revision 1.333
% diff -u -r1.333 rc
% --- rc        24 Jul 2004 16:30:31 -0000      1.333
% +++ rc        21 Sep 2004 09:34:08 -0000
% @@ -71,7 +71,20 @@
%  files=`rcorder -k ${os} ${skip} /etc/rc.d/* 2>/dev/null`
%
%  for _rc_elem in ${files}; do
% -     run_rc_script ${_rc_elem} ${_boot}
% +     case ${_rc_elem} in
% +     /etc/rc.d/selectcf)
% +             _sum_before=`md5 /etc/rc.conf`
% +             run_rc_script ${_rc_elem} ${_boot}
% +             _sum_after=`md5 /etc/rc.conf`
% +             if [ ! "${_sum_before}" = "${_sum_after}" ]; then
% +                     unset _rc_conf_loaded
% +                     load_rc_config 'XXX'
% +             fi
% +             ;;
% +     *)
% +             run_rc_script ${_rc_elem} ${_boot}
% +             ;;
% +     esac
%  done
%
%  echo ''



More information about the freebsd-questions mailing list