tech-userlevel archive

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

Re: rc.d/rndctl




On Fri, 19 Sep 2008, Alan Barrett wrote:
Yes, I think so.


Alan et al.:

I'm able to make it spin using bash -- our sh(1) seems to have trouble with the flag parsing on the inner-for-loop.

$ sudo bash   /etc/rc.d/rndctl start
DEBUG: Parsing argument substring: -c -e -t disk rng tty
DEBUG: /sbin/rndctl  -e -t disk
DEBUG: /sbin/rndctl  -e -t rng
DEBUG: /sbin/rndctl  -e -t tty
DEBUG: Parsing argument substring:  -c -t net
DEBUG: /sbin/rndctl -c -t net
DEBUG: Parsing argument substring:  -C -E -d sd0
DEBUG: /sbin/rndctl  -E -d sd0

rndctl=NO
rndctl_flags="-c -e -t disk rng tty; -c -t net; -C -E -d sd0"


But with sh:

$ sudo sh /etc/rc.d/rndctl start
Password:
DEBUG: Parsing argument substring: -c -e -t disk rng tty
DEBUG: /sbin/rndctl   -c -e -t disk rng tty
rndctl: unknown option --
usage: rndctl -CEce [-t devtype] [-d devname]
       rndctl -ls [-t devtype] [-d devname]
DEBUG: Parsing argument substring:  -c -t net
DEBUG: /sbin/rndctl    -c -t net
usage: rndctl -CEce [-t devtype] [-d devname]
       rndctl -ls [-t devtype] [-d devname]
DEBUG: Parsing argument substring:  -C -E -d sd0
DEBUG: /sbin/rndctl    -C -E -d sd0
usage: rndctl -CEce [-t devtype] [-d devname]
       rndctl -ls [-t devtype] [-d devname]

Bizarre -- I'm a bit over my head at this point ~BAS
#!/bin/sh
#
# $NetBSD$
#

# PROVIDE: rndctl
# BEFORE: cgd racoon ipsec sshd

$_rc_subr_loaded . /etc/rc.subr

name="rndctl"
rcvar=$name
command="/sbin/${name}"

start_cmd="rndctl_startcmd"


rndctl_startcmd() {

# Split on semicolons
IFS=';' eval set -- \$rndctl_flags
for args in "$@"; do
        # Within a single semicolon-separated segment,
        # parse zero or more flags followed by one or more devices.
        ceflags=''      # one or more of -c/-e/-C/-E 
        dtflags=''      # exactly one of -d/-t
        echo "DEBUG: Parsing argument substring: $args";
        for arg in ${args}; do
                case "${arg}" in
                        -[ceCE])
                                ceflags="${ceflags:+ }${arg}"
                                ;;
                        -[dt])
                                dtflags="${dtflags:+ }${arg}"
                                ;;
                        #-*)
                        #echo "Error";
                        #error
                        #;;
                        *)
                                # Perform the command with the specified
                                # device or type name.
                                # ceflags defaults to "-c -e".
                                # dtflags defaults to "-d".
                                dev="$arg"
                                #: ${ceflags:=-c -e}
                                #: ${dtflags:=-t}
                                echo "DEBUG: $command $ceflags $dtflags $dev"
                                $command ${ceflags} ${dtflags} ${dev}
                                ;;
                esac
        done
done
}

load_rc_config $name
run_rc_command "$1"


Home | Main Index | Thread Index | Old Index