HEADS UP: change in ports rc.d script behaviour

Mike Makonnen mtm at identd.net
Tue Jul 27 00:28:59 PDT 2004


On Mon, Jul 26, 2004 at 11:23:52AM +0000, Christian Weisgerber wrote:
> Craig Rodrigues <rodrigc at crodrigues.org> wrote:
> 
> > > 4. If you must include a default value for an rc.conf(5) knob,
> > >    make sure that you put it in an if [ -z "$foo_knob"] clause.
> > 
> > As a simple alternative to an if clause, I've done this for the 
> > isc-dhcp3-server port:
> > 
> > [ -z "$dhcpd_enable" ] && dhcpd_enable="NO"
> 
> dhcpd_enable=${dhcpd_enable:-NO}

Actually, when I was doing the patching yesterday, I realized that
my original suggestion wasn't correct. Yours is closer but still
wrong. It should be:
dhcpd_enable=${dhcpd_enable-"NO"}

This is because the ports scripts should define it *only* if the user
hasn't specified it. This isn't terribly important for an *_enable knob,
but it is crucial for something like foo_flags="". The ':-' modifier
to the parameter sets the variable if it doesn't exist or it's empty, while
the second only sets it if it doesn't exit. Here's an example:

The first and WRONG way: ${dhcpd_flags:-NO}:
rc.conf: dhcpd_flags=
rc.d/dhcpd.sh: dhcpd_flags="-x foo"
during execution: dhcpd_flags="-x foo"

The RIGHT way: ${dhcpd_flags-"-x foo"}
rc.conf: dhcpd_flags=
rc.d/dhcpd.sh: dhcpd_flags="-x foo"
during execution: dhcpd_flags=""

Cheers.
--
Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm at identd.net | Fingerprint: AC7B 5672 2D11 F4D0 EBF8  5279 5359 2B82 7CD4 1F55
mtm at FreeBSD.Org| FreeBSD - Unleash the Daemon !


More information about the freebsd-current mailing list