
carson at taltos
Nov 14, 2005, 7:20 PM
Post #4 of 8
(1032 views)
Permalink
|
|
Re: ocf-shellfuncs is broken in the last CVS
[In reply to]
|
|
--On Tuesday, November 15, 2005 10:04:45 AM +0800 Xun Sun <xun.sun.cn [at] gmail> wrote: > A question dumb maybe, what is your /bin/sh linked to? I have been > testing it on my Fedora Core 2 with /bin/sh linked to /bin/bash, and > all this works fine. Even "real" /bin/sh works with "set `/usr/bin/id`" (tested on Solaris). > --- ocf-shellfuncs.in 13 Nov 2005 17:00:02 -0000 1.22 > +++ ocf-shellfuncs.in 15 Nov 2005 02:01:40 -0000 > @@ -41,8 +41,9 @@ > . ${HA_D}/shellfuncs > > ocf_is_root() { > - set `/usr/bin/id` > - [ $1 = "uid=0(root)" ] > +# set `/usr/bin/id` > +# [ $1 = "uid=0(root)" ] > + [ $UID -eq 0 ] > } This is a portability loss - $UID is not set on all systems (certainly not in Solaris /bin/sh or /bin/ksh, or ksh93). The correct "fix" is to quote your variables inside the expression, and to handle strange id output better. If you want this to work in a pre-POSIX shell I'd suggest: id="`/usr/bin/id 2>/dev/null | cut -f1 -d\( | cut -f2 -d=`" [ -n "$id" -a "$id" -eq 0 ] (or perhaps id="`/usr/bin/id 2>/dev/null | sed -ne 's,^.*uid=\([0-9][0-9]*\).*$,\1,p'`") This would be even more robust, using XPG4 semantics if available, and falling back to guesswork parsing if not: id="" uid="" if [ -x /usr/xpg4/bin/id ]; then # Solaris id="/usr/xpg4/bin/id" elif [ -x /usr/bin/id ]; then id="/usr/bin/id" fi if [ -n "$id" ]; then uid="`$id -u 2>/dev/null`" if [ -z "$uid" ]; then uid="`$id 2>/dev/null | cut -f1 -d\( | cut -f2 -d=`" fi fi [ -n "$uid" -a "$uid" -eq 0 ] -- Carson _______________________________________________ Linux-HA mailing list Linux-HA [at] lists http://lists.linux-ha.org/mailman/listinfo/linux-ha See also: http://linux-ha.org/ReportingProblems
|