Order of items in rc.d scripts such as quota

Jilles Tjoelker jilles at stack.nl
Tue Jun 28 21:45:42 UTC 2011


This message is about a style issue of little relevance to correctness;
however, consistency in this regard is useful.

The conventional order of items in rc.d scripts appears to be
* comments and keywords
* source /etc/rc.subr and the like
* set variables like name, rcvar, start_cmd, stop_cmd
* define functions
* load_rc_config $name
* run_rc_command "$1"

A problem occurs when the variables to be set need rc.conf information.
In the case of start_cmd and stop_cmd this can always be avoided by
having them call a function (which could be done but was not done in the
recently fixed /etc/rc.d/quota, r223644, conf/157687), but this does not
work for some other variables like command_args (e.g. in
/etc/rc.d/ypxfrd).

A nasty thing about this is that /etc/rc.conf variables work even before
load_rc_config when the script is started from /etc/rc (initial boot and
shutdown) but not when the script is started directly or via service(8).
Variables from /etc/rc.conf.d or defaults work in neither case.

It would be safer to place load_rc_config directly below the name and
rcvar settings and any set_rcvar and set_rcvar_obsolete calls. This is
in fact exactly what r223644 does for /etc/rc.d/quota so this change
seems good even if it is somewhat different from many other rc.d
scripts.

-- 
Jilles Tjoelker


More information about the freebsd-rc mailing list