From harlan@mumps.pfcs.com  Sun Jun  1 21:23:11 1997
Received: from pcpsj.pfcs.com (pFgqLBzQ0cktG38Rcl2f8yfjaoTDDkJ7@harlan.fred.net [205.252.219.31])
          by hub.freebsd.org (8.8.5/8.8.5) with SMTP id VAA25175
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 1 Jun 1997 21:22:35 -0700 (PDT)
Received: from mumps.pfcs.com (mumps.pfcs.com [192.52.69.11]) by pcpsj.pfcs.com (8.6.12/8.6.9) with SMTP id AAA00518 for <FreeBSD-gnats-submit@freebsd.org>; Mon, 2 Jun 1997 00:22:23 -0400
Received: from localhost by mumps.pfcs.com with SMTP id AA02670
  (5.67b/IDA-1.5 for <FreeBSD-gnats-submit@freebsd.org>); Mon, 2 Jun 1997 00:22:22 -0400
Message-Id: <2668.865225341@mumps.pfcs.com>
Date: Mon, 02 Jun 1997 00:22:21 -0300
From: Harlan Stenn <Harlan.Stenn@pfcs.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: Improvements to /etc/rc{,.network,.pccard}
X-Send-Pr-Version: 3.2

>Number:         3751
>Category:       conf
>Synopsis:       Improvements to /etc/rc{,.network,.pccard}
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jun  1 21:30:01 PDT 1997
>Closed-Date:    Mon Mar 29 17:26:25 PST 1999
>Last-Modified:  Mon Mar 29 17:27:17 PST 1999
>Originator:     Harlan Stenn
>Release:        FreeBSD 2.2-current i386
>Organization:
PFCS Corporation
>Environment:

	-current (and before)

>Description:

	Several RC scripts use confusing syntax.  If I was really being a speed
	freak I'd replace the if [ ... ] stuff with case statements...

>How-To-Repeat:

	Examination.

>Fix:
	
	Untested...

--- rc-	Sun Jun  1 20:52:58 1997
+++ rc	Sun Jun  1 21:14:02 1997
@@ -29,7 +29,7 @@
 
 swapon -a
 
-if [ $1x = autobootx ]; then
+if [ "$1" = autoboot ]; then
 	echo Automatic reboot in progress...
 	fsck -p
 	case $? in
@@ -100,7 +100,7 @@
 
 
 # Add additional swapfile, if configured.
-if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
+if [ "$swapfile" != NO -a -w "$swapfile" -a -b /dev/vn0b ]; then
 	echo "Adding $swapfile as additional swap."
 	vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
 fi
@@ -133,13 +133,13 @@
 (cd /var/run && { cp /dev/null utmp; chmod 644 utmp; })
 
 # enable dumpdev so that savecore can see it
-if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} ]; then
+if [ "${dumpdev}" != NO -a -e ${dumpdev} ]; then
 	dumpon ${dumpdev}
 fi
 
 # /var/crash should be a directory or a symbolic link
 # to the crash directory if core dumps are to be saved.
-if [ "X${savecore_enable}" = X"YES" -a -d /var/crash ]; then
+if [ "${savecore_enable}" = YES -a -d /var/crash ]; then
 	echo -n checking for core dump...
 	savecore /var/crash
 fi
@@ -152,7 +152,7 @@
 # start system logging and name service (named needs to start before syslogd
 # if you don't have a /etc/resolv.conf)
 #
-if [ "X${syslogd_enable}" = X"YES" ]; then
+if [ "${syslogd_enable}" = YES ]; then
 	# Transitional symlink (for the next couple of years :) until all
 	# binaries had a chance to move towards /var/run/log.
 	if [ ! -h /dev/log ] ; then
@@ -164,7 +164,7 @@
 	echo -n ' syslogd';		syslogd ${syslogd_flags}
 fi
 
-if [ "X${tickadj_enable}" = X"YES" ]; then
+if [ "${tickadj_enable}" = YES ]; then
 	echo -n ' tickadj';	tickadj ${tickadj_flags--Aq}
 fi
 echo '.'
@@ -174,7 +174,7 @@
 fi
 
 # Check the quotas (must be after ypbind if using NIS)
-if [ "X${check_quotas}" = X"YES" ]; then
+if [ "${check_quotas}" = YES ]; then
 	echo -n 'checking quotas:'
 	quotacheck -a
 	echo ' done.'
@@ -197,7 +197,7 @@
 	"password file may be incorrect -- /etc/ptmp exists"
 fi
 
-if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
+if [ "${accounting_enable}" = YES -a -d /var/account ]; then
 	echo 'turning on accounting'
 	if [ ! -e /var/account/acct ]; then
 		touch /var/account/acct
@@ -220,11 +220,11 @@
 echo -n ' inetd';		inetd ${inetd_flags}
 echo -n ' cron';		cron
 
-if [ "X${lpd_enable}" = X"YES" ]; then
+if [ "${lpd_enable}" = YES ]; then
 	echo -n ' printer';		lpd ${lpd_flags}
 fi
 
-if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
+if [ "${sendmail_enable}" = YES -a -r /etc/sendmail.cf ]; then
 	echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
 fi
 
@@ -277,7 +277,7 @@
 fi
 
 # for each valid dir in $local_startup, search for init scripts matching *.sh
-if [ "X${local_startup}" != X"NO" ]; then
+if [ "${local_startup}" != NO ]; then
 	echo -n 'Local package startup:'
 	for dir in ${local_startup}; do
 		[ -d ${dir} ] && for script in ${dir}/*.sh; do
--- rc.network-	Sun Jun  1 20:52:58 1997
+++ rc.network	Sun Jun  1 21:15:56 1997
@@ -19,7 +19,7 @@
     fi
 
     # Set the domainname if we're using NIS
-    if [ -n "$nisdomainname" -a "x$nisdomainname" != "xNO" ] ; then
+    if [ -n "$nisdomainname" -a "$nisdomainname" != NO ] ; then
 	    domainname $nisdomainname
 	    echo -n ' domain'
     fi
@@ -56,18 +56,18 @@
     done
     
     # If IP filtering
-    if [ -n "$firewall" -a "x$firewall" != "xNO" -a -f /etc/rc.firewall ] ; then
+    if [ -n "$firewall" -a "$firewall" != NO -a -f /etc/rc.firewall ] ; then
 	    echo -n ' firewall'
 	    . /etc/rc.firewall
     fi
 
-    if [ "x$defaultrouter" != "xNO" ] ; then
+    if [ "$defaultrouter" != NO ] ; then
 	    static_routes="default ${static_routes}"
 	    route_default="default ${defaultrouter}"
     fi
     
     # Set up any static routes.  This should be done before router discovery.
-    if [ "x${static_routes}" != "x" ]; then
+    if [ "${static_routes}" != "" ]; then
 	    for i in ${static_routes}; do
 		    eval route_args=\$route_${i}
 		    route add ${route_args}
@@ -75,26 +75,26 @@
     fi
 
     echo -n 'Additional routing options:'
-    if [ "X$gateway_enable" = X"YES" ]; then
+    if [ "$gateway_enable" = YES ]; then
 	    echo -n ' IP gateway=YES'
 	    sysctl -w net.inet.ip.forwarding=1 >/dev/null 2>&1
     fi
     
-    if [ "X$router_enable" = X"YES" ]; then
+    if [ "$router_enable" = YES ]; then
 	    echo -n " ${router}";	${router} ${router_flags}
     fi
     
-    if [ "X$ipxgateway_enable" = X"YES" ]; then
+    if [ "$ipxgateway_enable" = YES ]; then
 	    echo -n ' IPX gateway=YES'
 	    sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 2>&1
     fi
     
-    if [ "X$ipxrouted_enable" = X"YES" ]; then
+    if [ "$ipxrouted_enable" = YES ]; then
 	    echo -n ' IPXrouted: '
 	    IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
     fi
     
-    if [ "X$arpproxy_all" = X"YES" ]; then
+    if [ "$arpproxy_all" = YES ]; then
 	    echo -n ' enabling ARP_PROXY_ALL: '
 	    sysctl -w net.link.ether.inet.proxyall=1 2>&1
     fi
@@ -104,51 +104,51 @@
 
 network_pass2() {
     echo -n 'Doing additional network setup:'
-    if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
+    if [ -n "$tcp_extensions" -a "$tcp_extensions" != YES ] ; then
 	    echo -n ' tcp extensions=NO'
 	    sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 2>&1
 	    sysctl -w net.inet.tcp.rfc1644=0 >/dev/null 2>&1
     fi
-    if [ "X${named_enable}" = X"YES" ]; then
+    if [ "${named_enable}" = YES ]; then
 	    echo -n ' named';		named ${named_flags}
     fi
 
-    if [ "X${ntpdate_enable}" = X"YES" -o "X${xntpd_enable}" = X"YES" ]; then
-	    if [ "X${ntpdate_enable}" = X"YES" ]; then
+    if [ "${ntpdate_enable}" = YES -o "${xntpd_enable}" = YES ]; then
+	    if [ "${ntpdate_enable}" = YES ]; then
 		    echo -n ' ntpdate';	ntpdate ${ntpdate_flags} >/dev/null 2>&1
 	    fi
 
-	    if [ "X${xntpd_enable}" = X"YES" ]; then
+	    if [ "${xntpd_enable}" = YES ]; then
 		    echo -n ' xntpd';	xntpd ${xntpd_flags}
 	    fi
     fi
 
-    if [ "X${timed_enable}" = X"YES" ]; then
+    if [ "${timed_enable}" = YES ]; then
 	    echo -n ' timed';		timed ${timed_flags}
     fi
 
-    if [ "X${portmap_enable}" = X"YES" ]; then
+    if [ "${portmap_enable}" = YES ]; then
 	    echo -n ' portmap';		portmap ${portmap_flags}
     fi
 
     # Start ypserv if we're an NIS server.
     # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
-    if [ "X${nis_server_enable}" = X"YES" ]; then
+    if [ "${nis_server_enable}" = YES ]; then
 	    echo -n ' ypserv'; ypserv ${nis_server_flags}
 	    
-	    if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then
+	    if [ "${nis_ypxfrd_enable}" = YES ]; then
 		    echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags}
 	    fi
 	    
-	    if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then
+	    if [ "${nis_yppasswdd_enable}" = YES ]; then
 		    echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags}
 	    fi
     fi
 
     # Start ypbind if we're an NIS client
-    if [ "X${nis_client_enable}" = X"YES" ]; then
+    if [ "${nis_client_enable}" = YES ]; then
 	    echo -n ' ypbind'; ypbind ${nis_client_flags}
-	    if [ "X${nis_ypset_enable}" = X"YES" ]; then
+	    if [ "${nis_ypset_enable}" = YES ]; then
 		    echo -n ' ypset'; ypset ${nis_ypset_flags}
 	    fi
     fi
@@ -160,47 +160,47 @@
 network_pass3() {
     echo -n 'Starting final network daemons:'
 
-    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
+    if [ "${nfs_server_enable}" = YES -a -r /etc/exports ]; then
 	    echo -n ' mountd'
-	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
+	    if [ "${weak_mountd_authentication}" = YES ]; then
 		    mountd_flags="-n"
 	    fi
 	    mountd ${mountd_flags}
-	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
+	    if [ "${nfs_reserved_port_only}" = YES ]; then
 		    echo -n ' nfsprivport=YES'
 		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 2>&1
 	    fi
 	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
-	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
+	    if [ "$rpc_lockd_enable" = YES ]; then
 		echo -n ' rpc.lockd';		rpc.lockd
 	    fi
-	    if [ "X$rpc_statd_enable" = X"YES" ]; then
+	    if [ "$rpc_statd_enable" = YES ]; then
 		echo -n ' rpc.statd';		rpc.statd
 	    fi
     fi
     
-    if [ "X${nfs_client_enable}" = X"YES" ]; then
+    if [ "${nfs_client_enable}" = YES ]; then
 	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
     fi
 
-    if [ "X${amd_enable}" = X"YES" ]; then
+    if [ "${amd_enable}" = YES ]; then
 	    echo -n ' amd'
 	    amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
     fi
 
-    if [ "X${rwhod_enable}" = X"YES" ]; then
+    if [ "${rwhod_enable}" = YES ]; then
 	    echo -n ' rwhod';	rwhod
     fi
 
     # Kerberos runs ONLY on the Kerberos server machine
-    if [ "X${kerberos_server_enable}" = X"YES" ]; then
+    if [ "${kerberos_server_enable}" = YES ]; then
 	    echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
 	    echo -n ' kadmind'; \
 		    (sleep 20; kadmind -n >/dev/null 2>&1 &) &
     fi
     
     # IP multicast routing daemon
-    if [ "X${mrouted_enable}" = X"YES" ]; then
+    if [ "${mrouted_enable}" = YES ]; then
 	    echo -n ' mrouted'; mrouted ${mrouted_flags}
     fi
     echo '.'
--- rc.pccard-	Sun Jun  1 20:52:58 1997
+++ rc.pccard	Sun Jun  1 21:16:06 1997
@@ -4,8 +4,8 @@
 # HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
 #
 
-if [ "X$pccard_enable" = X"YES" ] ; then
-	if [ "x$pccard_mem" != "xDEFAULT" ] ; then
+if [ "$pccard_enable" = YES ] ; then
+	if [ "$pccard_mem" != DEFAULT ] ; then
 		pccardc pccardmem $pccard_mem
 	else
 		pccardc pccardmem 0xd0000

>Release-Note:
>Audit-Trail:

From: j@uriah.heep.sax.de (J Wunsch)
To: Harlan.Stenn@pfcs.com (Harlan Stenn)
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/3751: Improvements to /etc/rc{,.network,.pccard}
Date: Mon, 2 Jun 1997 08:50:31 +0200

 As Harlan Stenn wrote:
 
 > 	Several RC scripts use confusing syntax.  If I was really being a speed
 > 	freak I'd replace the if [ ... ] stuff with case statements...
 
 > -if [ $1x = autobootx ]; then
 > +if [ "$1" = autoboot ]; then
 
 That's not entirely confusing syntax.  It's normal habit to be on the
 safe side.  Although i agree, the quotes should always be there, and
 the X should always be prepended.
 
 Prepending the X saves you from hidden gotchas like in:
 
 foo="-ain't this weird?-"
 
 if [ "$foo" = "bar" ] ; ...
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)

From: Harlan Stenn <Harlan.Stenn@pfcs.com>
To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/3751: Improvements to /etc/rc{,.network,.pccard} 
Date: Mon, 02 Jun 1997 04:56:19 -0300

 >>> On Mon, 2 Jun 1997 08:50:31 +0200, j@uriah.heep.sax.de (J Wunsch) said:
 
 H> -if [ $1x = autobootx ]; then +if [ "$1" = autoboot ]; then
 
 J> That's not entirely confusing syntax.  It's normal habit to be on the
 J> safe side.  Although i agree, the quotes should always be there,
 
 Agreed (obviously)
 
 J> and the X should always be prepended.
 
 I don't think it should ever be there, but if it must be there, it
 should be prepended.
 
 J> Prepending the X saves you from hidden gotchas like in:
 
 J> foo="-ain't this weird?-"
 
 J> if [ "$foo" = "bar" ] ; ...
 
 Did you mean:
 
    if [ $foo = "bar" ] ; ... 
 
 Shell metacharacters aren't expanded with "$foo".
 
 Regardless, if you're talking about the shell metacharacter problem, I'd
 disagree with you about the "hidden gotcha".
 
 Quoting and shell metacharacters are such basic concepts that anybody
 who writes a shell script should be aware of them.  And besides, invoking
 "sh -x script" will quickly show the problem.
 
 As an aside, in "rc" the quoting checking vi.recover is also
 inconsistent...
 
 H
 
 

From: j@uriah.heep.sax.de (J Wunsch)
To: Harlan.Stenn@pfcs.com (Harlan Stenn)
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/3751: Improvements to /etc/rc{,.network,.pccard}
Date: Mon, 2 Jun 1997 21:21:11 +0200

 As Harlan Stenn wrote:
 
 > J> foo="-ain't this weird?-"
 > 
 > J> if [ "$foo" = "bar" ] ; ...
 > 
 > Did you mean:
 > 
 >    if [ $foo = "bar" ] ; ... 
 > 
 > Shell metacharacters aren't expanded with "$foo".
 
 No, i meant the problem that arises if $foo evaluates to something
 that could become a valid switch for test(1).
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)

From: Harlan Stenn <Harlan.Stenn@pfcs.com>
To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/3751: Improvements to /etc/rc{,.network,.pccard} 
Date: Tue, 03 Jun 1997 03:54:29 -0300

 J> foo="-ain't this weird?-"
 
 J> if [ "$foo" = "bar" ] ; ...
 >>  Did you mean:
 >> 
 >> if [ $foo = "bar" ] ; ...
 >> 
 >> Shell metacharacters aren't expanded with "$foo".
 
 J> No, i meant the problem that arises if $foo evaluates to something
 J> that could become a valid switch for test(1).
 
 Oh.  That's a problem, and another reason why I often prefer a case statement.
 
 The good news is that in none of the places I've changed would this be
 the case.
 
 H
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Mar 29 17:26:25 PST 1999 
State-Changed-Why:  
All the bits the originator is unhappy with are commonly used idioms 
and it doesn't look like anyone's keen on committing his first hunk. 
>Unformatted:
