From owner-freebsd-doc@FreeBSD.ORG Sun Oct 14 13:10:00 2012 Return-Path: Delivered-To: freebsd-doc@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8F8515AA for ; Sun, 14 Oct 2012 13:10:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [8.8.178.135]) by mx1.freebsd.org (Postfix) with ESMTP id 66AB88FC16 for ; Sun, 14 Oct 2012 13:10:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q9EDA0dM083904 for ; Sun, 14 Oct 2012 13:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q9EDA0iL083903; Sun, 14 Oct 2012 13:10:00 GMT (envelope-from gnats) Resent-Date: Sun, 14 Oct 2012 13:10:00 GMT Resent-Message-Id: <201210141310.q9EDA0iL083903@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-doc@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Chris Rees Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 276464A1 for ; Sun, 14 Oct 2012 13:02:51 +0000 (UTC) (envelope-from crees@bayofrum.net) Received: from mk-outboundfilter-2.mail.uk.tiscali.com (mk-outboundfilter-2.mail.uk.tiscali.com [212.74.114.38]) by mx1.freebsd.org (Postfix) with ESMTP id A58398FC0A for ; Sun, 14 Oct 2012 13:02:50 +0000 (UTC) Received: from 212-139-242-85.dynamic.dsl.as9105.com (HELO pegasus.bayofrum.net) ([212.139.242.85]) by smtp.pipex.tiscali.co.uk with ESMTP; 14 Oct 2012 14:02:48 +0100 Received: by pegasus.bayofrum.net (Postfix, from userid 1001) id 837AD4D332; Sun, 14 Oct 2012 14:02:39 +0100 (BST) Message-Id: <20121014130239.837AD4D332@pegasus.bayofrum.net> Date: Sun, 14 Oct 2012 14:02:39 +0100 (BST) From: Chris Rees To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: docs/172692: [PATCH] Bring parts of the rc scripting guides up to date X-BeenThere: freebsd-doc@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Chris Rees List-Id: Documentation project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Oct 2012 13:10:00 -0000 >Number: 172692 >Category: docs >Synopsis: [PATCH] Bring parts of the rc scripting guides up to date >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Oct 14 13:10:00 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Chris Rees >Release: FreeBSD 9.0-RELEASE amd64 >Organization: >Environment: System: FreeBSD pegasus.bayofrum.net 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Sun Apr 29 12:29:02 BST 2012 root@pegasus.bayofrum.net:/usr/obj/usr/src/sys/PEGASUS amd64 >Description: The RC scripting guide is a little out of date, since it doesn't match current practice. Also, tighten up on some terminology. >How-To-Repeat: >Fix: --- rc-scripting-modernise.diff begins here --- Index: article.xml =================================================================== --- article.xml (revision 39747) +++ article.xml (working copy) @@ -400,8 +400,8 @@ stop_cmd=":" load_rc_config $name -eval "${rcvar}=\${${rcvar}:-'NO'}" -dummy_msg=${dummy_msg:-"Nothing started."} +: ${dummy_enable:=no} +: ${dummy_msg="Nothing started."} dummy_start() { @@ -448,7 +448,7 @@ system, you should add a default setting for the knob to /etc/defaults/rc.conf and document it in &man.rc.conf.5;. Otherwise it is your script that - should provide a default setting for the knob. A portable + should provide a default setting for the knob. The canonical approach to the latter case is shown in the example. @@ -479,7 +479,7 @@ The names of all &man.rc.conf.5; variables used exclusively by our script must - have the same prefix: ${name}. For + have the same prefix: ${name}_. For example: dummy_mode, dummy_state_file, and so on. @@ -491,15 +491,6 @@ our script will save us from possible collisions with the &man.rc.subr.8; namespace. - As long as an &man.rc.conf.5; variable and its - internal equivalent are the same, we can use a more - compact expression to set the default value: - - : ${dummy_msg:="Nothing started."} - - The current style is to use the more verbose form - though. - As a rule, rc.d scripts of the base system need not provide defaults for their &man.rc.conf.5; variables because the defaults should @@ -512,7 +503,11 @@ Here we use dummy_msg to actually - control our script, i.e., to emit a variable message. + control our script, i.e., to emit a variable message. + Use of a shell function is overkill here, since it only + runs a single command; an equally valid alternative is: + + start_cmd="echo \"$dummy_msg\"" --- rc-scripting-modernise.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: