tech-userlevel archive

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

Re: rc.d/rndctl



    Date:        Mon, 3 Nov 2008 17:17:34 -0500 (EST)
    From:        "Brian A. Seklecki" <lavalamp%spiritual-machines.org@localhost>
    Message-ID:  <20081103163927.X5180%arbitor.digitalfreaks.org@localhost>

  |   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.

Just by inspection, the script is obviously bogus (though whether
that makes a difference to the sh/bash distinction I don't know,
but I suspect not, that looks to be a different problem.)

  | 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]

The unknown option is presumably a null string at the start (the extra
space between rndctl and -c).  Just why that's appearing I'm not sure,
it may be a but on the processing of IFS=';' eval ... perhaps not
restoring IFS for the outer shell the way it should.  Your debug output
suggests a problem like that.

But in the script, and assuming that in
        ceflags=''      # one or more of -c/-e/-C/-E 
        dtflags=''      # exactly one of -d/-t
the comments there describe what is intended, then

                case "${arg}" in
                        -[ceCE])
                                ceflags="${ceflags:+ }${arg}"

isn't doing the correct thing, that will take the last of the -c e -C -E
args, and precede it with a (meaningless, or should be) space if there was
an earlier option from that set.   Almost certainly what was intended was

                                ceflags="${ceflags}${ceflags:+ }${arg}"

And then
                        -[dt])
                                dtflags="${dtflags:+ }${arg}"

looks as if it was intending to do the same thing, but according to
the earlier comments, that would be wrong, just one of the -d and -t
args should be permitted, to follow accepted practice, that's usually
the last one seen, so ...

                                dtflags=${arg}

should do the trick (no quoting needed, though it also should do no harm).

[Aside, and last, in the default case, the variable "dev" isn't really
needed, the script can just use $arg where it uses $dev ad skip the
dev=$arg assignment).

To test for the sh bug with IFS handling that I suspect, change the

        IFS=';' eval set -- \$rndctl_flags

line at the start of the function to

        oIFS=$IFS
        IFS=';'
        set -- $rndctl_flags
        IFS=$oIFS

and see if that allows the script to work with sh (which system version
are you using?   sh has had several bugs fixed recently.)

kre



Home | Main Index | Thread Index | Old Index