Hi David, In this commit you defined ocf_is_hexadecimal in ocf-shellfuncs.in, but used ocf_is_hex in other places, which looks inconsistent to me. Unfortunately you seem unaware of this problem even though I mentioned it in my last two mails ;-)
So I have just committed a one-liner fix for this. Feel free to change to other appropriate things. On 11/12/05, [email protected] <[email protected]> wrote: > linux-ha CVS committal > > Author : davidlee > Host : > Project : linux-ha > Module : resources > > Dir : linux-ha/resources/OCF > > > Modified Files: > ocf-shellfuncs.in IPaddr.in IPaddr2.in drbd.in > > > Log Message: > Some bash-isms were making the OCF "sh" scripts non-portable. > Also identified some common code blocks, and separated these > out into "resources/OCF/ocf-shellfuncs.in". > > Files in this update: > resources/OCF/ocf-shellfuncs.in > resources/OCF/IPaddr.in > resources/OCF/IPaddr2.in > resources/OCF/drbd.in > > =================================================================== > RCS file: /home/cvs/linux-ha/linux-ha/resources/OCF/ocf-shellfuncs.in,v > retrieving revision 1.19 > retrieving revision 1.20 > diff -u -3 -r1.19 -r1.20 > --- ocf-shellfuncs.in 26 Oct 2005 11:34:49 -0000 1.19 > +++ ocf-shellfuncs.in 11 Nov 2005 16:15:02 -0000 1.20 > @@ -1,5 +1,5 @@ > # > -# $Id: ocf-shellfuncs.in,v 1.19 2005/10/26 11:34:49 andrew Exp $ > +# $Id: ocf-shellfuncs.in,v 1.20 2005/11/11 16:15:02 davidlee Exp $ > # > # Common helper functions for the OCF Resource Agents supplied by > # heartbeat. > @@ -40,6 +40,26 @@ > __SCRIPT_NAME=`basename $0` > . ${HA_D}/shellfuncs > > +ocf_is_root() { > + set `/usr/bin/id` > + [ $1 = "uid=0(root)" ] > +} > + > +ocf_is_decimal() { > + # test: delete all decimal digits: result should be zero-length > + [ -z "`echo $1 | tr -d '[0-9]'`" ] > +} > + > +ocf_is_hexadecimal() { > + # test: delete all hex digits: result should be zero-length > + [ -z "`echo $1 | tr -d '[0-9a-fA-F]'`" ] > +} > + > +ocf_is_octal() { > + # test: delete all octal digits: result should be zero-length > + [ -z "`echo $1 | tr -d '[0-7]'`" ] > +} > + > __ocf_set_defaults() { > __OCF_ACTION="$1" > > =================================================================== > RCS file: /home/cvs/linux-ha/linux-ha/resources/OCF/IPaddr.in,v > retrieving revision 1.28 > retrieving revision 1.29 > diff -u -3 -r1.28 -r1.29 > --- IPaddr.in 8 Nov 2005 02:08:57 -0000 1.28 > +++ IPaddr.in 11 Nov 2005 16:15:02 -0000 1.29 > @@ -43,7 +43,8 @@ > USAGE="usage: $0 {start|stop|status|monitor|validate-all|meta-data}"; > > ####################################################################### > -export LC_ALL=C > +LC_ALL=C > +export LC_ALL > > [EMAIL PROTECTED]@/ha.d > . ${HA_D}/shellfuncs > @@ -194,7 +195,7 @@ > } > > ip_init() { > - if [ $UID -ne 0 ]; then > + if ocf_is_root ; then : ; else > ocf_log err "You must be root." > exit $OCF_ERR_PERM > fi > @@ -223,11 +224,11 @@ > exit $OCF_ERR_GENERIC > fi > > - if [ -z ${OCF_RESKEY_lvs_support} ]; then > + if [ -z "${OCF_RESKEY_lvs_support}" ]; then > LVS_SUPPORT=0 > - elif [ ${OCF_RESKEY_lvs_support} = "true" > - -o ${OCF_RESKEY_lvs_support} = "on" > - -o ${OCF_RESKEY_lvs_support} = "1" ]; then > + elif [ x"${OCF_RESKEY_lvs_support}" = x"true" > + -o x"${OCF_RESKEY_lvs_support}" = x"on" > + -o x"${OCF_RESKEY_lvs_support}" = x"1" ]; then > LVS_SUPPORT=1 > else > LVS_SUPPORT=0 > @@ -554,8 +555,8 @@ > fi;; > esac > > - if [ ! -z ${OCF_RESKEY_local_stop_script} ]; then > - if [ -x ${OCF_RESKEY_local_stop_script} ]; then > + if [ ! -z "${OCF_RESKEY_local_stop_script}" ]; then > + if [ -x "${OCF_RESKEY_local_stop_script}" ]; then > ${OCF_RESKEY_local_stop_script} $* > fi > fi > @@ -723,8 +724,8 @@ > *) ;; > esac > fi > - if [ ! -z ${OCF_RESKEY_local_start_script} ]; then > - if [ -x ${OCF_RESKEY_local_start_script} ]; then > + if [ ! -z "${OCF_RESKEY_local_start_script}" ]; then > + if [ -x "${OCF_RESKEY_local_start_script}" ]; then > ${OCF_RESKEY_local_start_script} $* > fi > fi > @@ -835,12 +836,7 @@ > } > > is_positive_integer() { > -# We know $1 is non-empty beforehand > - case $1 in > - *[^0-9]*) false;; #got invalid char > - *[1-9]*) true;; #no invalid char, at most one decimal point, contains > non-zero digit <=> valid > - *) false;; #"0" string > - esac > + ocf_is_decimal $1 && [ $1 -ge 1 ] > } > > ip_validate_all() { > =================================================================== > RCS file: /home/cvs/linux-ha/linux-ha/resources/OCF/IPaddr2.in,v > retrieving revision 1.13 > retrieving revision 1.14 > diff -u -3 -r1.13 -r1.14 > --- IPaddr2.in 1 Nov 2005 03:32:41 -0000 1.13 > +++ IPaddr2.in 11 Nov 2005 16:15:02 -0000 1.14 > @@ -1,6 +1,6 @@ > #!/bin/sh > # > -# $Id: IPaddr2.in,v 1.13 2005/11/01 03:32:41 xunsun Exp $ > +# $Id: IPaddr2.in,v 1.14 2005/11/11 16:15:02 davidlee Exp $ > # > # OCF Resource Agent compliant IPaddr2 script. > # > @@ -224,16 +224,8 @@ > exit $OCF_SUCCESS > } > > -is_decimal() { > -# We know $1 is non-empty beforehand > - case $1 in > - *[^0-9]*) false;; #got invalid char > - *) true;; > - esac > -} > - > ip_init() { > - if [ $UID -ne 0 ]; then > + if ocf_is_root ; then : ; else > ocf_log err "You must be root." > exit $OCF_ERR_PERM > fi > @@ -260,7 +252,7 @@ > ARP_BACKGROUND=${OCF_RESKEY_arp_bg:-yes} > ARP_NETMASK=${OCF_RESKEY_arp_mac:-ffffffffffff} > > - if is_decimal "$IP_INC_GLOBAL" && [ $IP_INC_GLOBAL -gt 0 ]; then > + if ocf_is_decimal "$IP_INC_GLOBAL" && [ $IP_INC_GLOBAL -gt 0 ]; then > : > else > ocf_log err "Invalid OCF_RESKEY_incarnations_max_global > [$IP_INC_GLOBAL], should be positive integer" > @@ -661,36 +653,20 @@ > esac > } > > -is_hexidecimal() { > -# We know $1 is non-empty beforehand > - case $1 in > - *[^0-9a-fA-F]*) false;; #got invalid char > - *) true;; > - esac > -} > - > -is_octal() { > -# We know $1 is non-empty beforehand > - case $1 in > - *[^0-7]*) false;; #got invalid char > - *) true;; > - esac > -} > - > ip_validate() { > ip_init > > # $BASEIP, $NETMASK, $NIC , $IP_INC_GLOBAL, and $BRDCAST have been checked > within ip_init, > # do not bother here. > > - if is_decimal "$ARP_INTERVAL_MS" && [ $ARP_INTERVAL_MS -gt 0 ]; then > + if ocf_is_decimal "$ARP_INTERVAL_MS" && [ $ARP_INTERVAL_MS -gt 0 ]; then > : > else > ocf_log err "Invalid OCF_RESKEY_arp_interval [$ARP_INTERVAL_MS]" > exit $OCF_ERR_ARGS > fi > > - if is_decimal "$ARP_REPEAT" && [ $ARP_REPEAT -gt 0 ]; then > + if ocf_is_decimal "$ARP_REPEAT" && [ $ARP_REPEAT -gt 0 ]; then > : > else > ocf_log err "Invalid OCF_RESKEY_arp_count [$ARP_REPEAT]" > @@ -719,7 +695,7 @@ > case $mark in > 0x*) # hexidecimal > mark=$(echo $mark | cut -c 3-) > - if [ -n "$mark" ] && is_hexidecimal "$mark"; then > + if [ -n "$mark" ] && ocf_is_hex "$mark"; then > : > else > valid=0 > @@ -727,14 +703,14 @@ > ;; > 0*) # octal > mark=$(echo $mark | cut -c 2-) > - if [ -n "$mark" ] && is_octal "$mark"; then > + if [ -n "$mark" ] && ocf_is_octal "$mark"; then > : > else > valid=0 > fi > ;; > *) # decimal > - if [ -n "$mark" ] && is_decimal "$mark"; then > + if [ -n "$mark" ] && ocf_is_decimal "$mark"; then > : > else > valid=0 > @@ -750,7 +726,7 @@ > case $IF_MAC in > ??[^0-9]??[^0-9]??[^0-9]??[^0-9]??[^0-9]??) > > mac=${IF_MAC:0:2}${IF_MAC:3:2}${IF_MAC:6:2}${IF_MAC:9:2}${IF_MAC:12:2}${IF_MAC:15:2} > - if is_hexidecimal "$mac"; then > + if ocf_is_hex "$mac"; then > case ${mac:1:1} in > 0|2|4|6|8|a|A|c|C|e|E) > valid=0 > =================================================================== > RCS file: /home/cvs/linux-ha/linux-ha/resources/OCF/drbd.in,v > retrieving revision 1.14 > retrieving revision 1.15 > diff -u -3 -r1.14 -r1.15 > --- drbd.in 7 Nov 2005 15:44:22 -0000 1.14 > +++ drbd.in 11 Nov 2005 16:15:02 -0000 1.15 > @@ -1,6 +1,6 @@ > #!/bin/sh > # > -# $Id: drbd.in,v 1.14 2005/11/07 15:44:22 xunsun Exp $ > +# $Id: drbd.in,v 1.15 2005/11/11 16:15:02 davidlee Exp $ > # > # OCF Resource Agent compliant drbd resource script. > # > @@ -480,7 +480,7 @@ > drbd_validate_all > ;; > start|stop|monitor|promote|demote|notify) > - if [ $UID -ne 0 ]; then > + if ocf_is_root ; then : ; else > ocf_log err "You must be root to perform this > operation." > exit $OCF_ERR_PERM > fi > > > _______________________________________________ > Linux-ha-cvs mailing list > [email protected] > http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs > -- Thanks & regards Xun Sun _______________________________________________________ Linux-HA-Dev: [email protected] http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev Home Page: http://linux-ha.org/
