On Sun, 13 Nov 2005, Lars Ellenberg wrote:

/ 2005-11-13 12:38:52 +0000
\ David Lee:
[...]
 ocf_is_decimal() {
-        # test: delete all decimal digits: result should be zero-length
-        [ -z "`echo $1 | tr -d '[0-9]'`" ]
+       case "$1" in
+       *[!0-9]*)       # got invalid char
+               false ;;
+       *)
+               true ;;
+       esac
 }

probably not important at all, and I may miss the point, but:
is undefined/empty a valid decimal/hexadecimal/octal?
if not:
     ""|*[!0-9]*) false;; # empty or invalid character
     ^^^
or similar

Sneaky! Thanks. Earlier (and other current) incarnations of the "case" code do, indeed, treat the empty string as invalid, or had comments such as:
   We know $1 is non-empty beforehand

So I think your modification is correct.

(Reminder: this is, in principle, reverting to the previous "case"-based
algorithm, but with "!" rather than "^" as the negation character in the pattern-match.)

I have applied the patch (with Lars's adjustment).

Next step: Perhaps someone with a Linux-based run-time environment should look at:
   resources/OCF/apache.in
   resources/OCF/portblock.in
   resources/OCF/WAS.in
   resources/OCF/Xinetd.in

(and others?), which have internal functions such as "CheckPort" and "CheckInteger" that ought to be rationalised onto these "ocf_is_decimal" (etc.) functions. (I could do this myself, but probably should not, because I'd be doing it "blind", being unable to run-time check it!)

--

:  David Lee                                I.T. Service          :
:  Senior Systems Programmer                Computer Centre       :
:                                           Durham University     :
:  http://www.dur.ac.uk/t.d.lee/            South Road            :
:                                           Durham DH1 3LE        :
:  Phone: +44 191 334 2752                  U.K.                  :
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to