Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/etc rc.subr can be used in install images (from sysinst) so ...



details:   https://anonhg.NetBSD.org/src/rev/6f05b6c4e138
branches:  trunk
changeset: 836048:6f05b6c4e138
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Sep 23 23:02:39 2018 +0000

description:
rc.subr can be used in install images (from sysinst) so must use only
POSIX specified test uses (no -a or -o).   Also, use printf always,
rather than echo (replace echo as a function using echo with one which
uses printf).

diffstat:

 etc/rc.subr |  35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diffs (110 lines):

diff -r 6c9580fd9f73 -r 6f05b6c4e138 etc/rc.subr
--- a/etc/rc.subr       Sun Sep 23 21:44:01 2018 +0000
+++ b/etc/rc.subr       Sun Sep 23 23:02:39 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: rc.subr,v 1.102 2018/04/11 18:51:22 christos Exp $
+# $NetBSD: rc.subr,v 1.103 2018/09/23 23:02:39 kre Exp $
 #
 # Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -85,7 +85,9 @@
 
        checkyesnox $1
        var=$?
-       [ $var = 0 -o $var = 1 ] && return $var
+       case "${var}" in
+       ( 0 | 1 )       return $var;;
+       esac
        warn "\$${1} is not set properly - see ${rcvar_manpage}."
        return 1
 }
@@ -209,7 +211,7 @@
        _pidfile=$1
        _procname=$2
        _interpreter=$3
-       if [ -z "$_pidfile" -o -z "$_procname" ]; then
+       if [ -z "$_pidfile" ] || [ -z "$_procname" ]; then
                err 3 'USAGE: check_pidfile pidfile procname [interpreter]'
        fi
        if [ ! -f $_pidfile ]; then
@@ -523,7 +525,7 @@
        _procname=${procname:-${command}}
 
                                        # setup pid check command if not fast
-       if [ -z "$rc_fast" -a -n "$_procname" ]; then
+       if [ -z "$rc_fast" ] && [ -n "$_procname" ]; then
                if [ -n "$pidfile" ]; then
                        _pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')'
                else
@@ -561,7 +563,7 @@
                                        # and return if that failed or warn
                                        # user and exit when interactive
                                        #
-       if [ -n "${rcvar}" -a "$rc_arg" != "rcvar" ]; then
+       if [ -n "${rcvar}" ] && [ "$rc_arg" != "rcvar" ]; then
                if ! checkyesno ${rcvar}; then
                                        # check whether interactive or not
                        if [ -n "$_run_rc_script" ]; then
@@ -849,7 +851,7 @@
 {
        _file=$1
        _arg=$2
-       if [ -z "$_file" -o -z "$_arg" ]; then
+       if [ -z "$_file" ] || [ -z "$_arg" ]; then
                err 3 'USAGE: run_rc_script file arg'
        fi
 
@@ -940,7 +942,7 @@
        fi
        eval $(eval '(
                load_rc_config '$1' >/dev/null;
-               if [ -n "${'$2'}" -o "${'$2'-UNSET}" != "UNSET" ]; then
+               if [ -n "${'$2'}" ] || [ "${'$2'-UNSET}" != "UNSET" ]; then
                        echo '$2'=\'\''${'$2'}\'\'';
                fi
        )' )
@@ -1039,7 +1041,7 @@
                # current backup is not lost
                if [ -f $_cur ]; then
                        # no archive, or current newer than archive
-                       if [ ! -f $_cur,v -o $_cur -nt $_cur,v ]; then
+                       if [ ! -f $_cur,v ] || [ $_cur -nt $_cur,v ]; then
                                ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
                                rcs -q -kb -U $_cur
                                co -q -f -u $_cur
@@ -1339,13 +1341,25 @@
 # will call these functions.  To call the real echo and printf
 # commands, use "command echo" or "command printf".
 #
+# Avoid use of echo altogether as much as possible, printf works better
+#
 echo()
 {
-       command echo "$@"
+       local IFS=' ' NL='\n'   # not a literal newline...
+
        case "$1" in
-       '-n')   _flush_rc_output ;;
+       -n)     NL=; shift;;
        esac
+
+       command printf "%s${NL}" "$*"
+
+       if test -z "${NL}"
+       then
+               _flush_rc_output
+       fi
+       return 0
 }
+
 printf()
 {
        command printf "$@"
@@ -1353,6 +1367,7 @@
        *'\n')  : ;;
        *)      _flush_rc_output ;;
        esac
+       return 0
 }
 
 kat() {



Home | Main Index | Thread Index | Old Index