RFC: set_rcvar in rc.subr

From: Hiroki Sato <hrs_at_FreeBSD.org>
Date: Tue, 07 Jul 2009 07:05:45 +0900 (JST)
Hi,

 I would like to propose an expansion of set_rcvar() in rc.subr.  The
 motivation and the change are the following.

 The current rc.d scripts depend on variables defined in
 /etc/defaults/rc.conf. However, it is unclear that which variables
 are used in a script and assigning a default value to a variable is
 scattered and inconsistent.  Also, it is difficult to detect
 definition of obsolete variables in /etc/rc.conf and
 /etc/defaults/rc.conf.

 The proposed changes are:

 1. Add a functionality to declare a rc.conf variable and its default
    value to set_rcvar().  The syntax is:

    set_rcvar <varname> <defvalue> <desc>

    The declared variables are set by load_rc_config().  Note that
    this behavior of set_rcvar() is backward compatible.

    For example, a script for routed(8) will be something like this:

    ----
    name="routed"
    rcvar=`set_rcvar`

    set_rcvar ${name}_enable NO
    set_rcvar ${name}_flags "-q" \
        "Flags for ${name}(8)."
    set_rcvar ${name}_program "/usr/sbin/routed" \
        "Program name for ${name}(8)."

    load_rc_config $name
    run_rc_command "$1"
    ----

 2. Display the declared variables by "rc.d/foo rcvar" with
    the default value and description like this:

    % /etc/rc.d/routed rcvar
    # routed : network RIP and router discovery routing daemon
    #
    routed_enable="NO"
    #   (default: "NO")
    routed_flags="-q"
    # - Flags for routed(8).
    #   (default: "-q")
    routed_program="/sbin/routed"
    # - Program name for routed(8).
    #   (default: "/usr/sbin/routed")

    It should be easier to understand the variables than the current
    /etc/defaults/rc.conf and always consistent.

    To do this, all of rc.d scripts have to have run_rc_command()
    while currently some scripts which always run have no $rcvar and
    run_rc_command().  Adding run_rc_command() becomes no problem and
    rather good for consistency, IMHO.  Also, $desc is added for
    description of the script displayed in above example.

    Entries for each rc.d script in /etc/defaults/rc.conf can be
    removed, and the equivalent contents can be generated by the
    following command:

    # for F in `rcorder /etc/rc.d/*`; do $F rcvar; done

 3. Add a way to obsolete a variable.  This is done by adding
    set_rcvar_obsolete() function.

    set_rcvar_obsolete <oldvar> <newvar>

    If <oldvar> is defined, do newvar=$oldvar and display a warning in
    load_rc_config().  This makes easier to detect an obsolete
    variable in an old rc.conf file.

 The attached patch is a working example.  If there is no strong
 objection I want to convert all of the current rc.d scripts in this
 way.  Note that this patch include a change not directly related to
 the above; handling $_override_command in run_rc_command() looks
 wrong to me.  When ${name}_program is defined and $command is not the
 former is used as the command, and if $command is defined directly it
 is used by priority.

 Comments or objections?

-- Hiroki

Received on Mon Jul 06 2009 - 20:11:23 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:51 UTC