Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux-HA: Users

ocf-shellfuncs is broken in the last CVS

 

 

Linux-HA users RSS feed   Index | Next | Previous | View Threaded


sergeyfd at gmail

Nov 14, 2005, 11:19 AM

Post #1 of 8 (1138 views)
Permalink
ocf-shellfuncs is broken in the last CVS

Hello -
After checking out the latest CVS version of Linux-HA everything stopped to
work because of the problem in the ocf-shellfuncs.org<http://ocf-shellfuncs.org>
:
[ $1 = "uid=0(root)" ]
This line in the ocf_is_root function causes following error message: line
45: [: =: unary operator expected
Also this line:
set `/usr/bin/id`
in the same script ans the same function causes printing a whole
environment on the screen.
Linux version installed is Mandrakelinux release 10.1


xun.sun.cn at gmail

Nov 14, 2005, 6:04 PM

Post #2 of 8 (1095 views)
Permalink
Re: ocf-shellfuncs is broken in the last CVS [In reply to]

Hi Serge,
On 11/15/05, Serge Dubrouski <sergeyfd [at] gmail> wrote:
> Hello -
>
> After checking out the latest CVS version of Linux-HA everything stopped to
> work because of the problem in the ocf-shellfuncs.org:
>
> [ $1 = "uid=0(root)" ]
>
> This line in the ocf_is_root function causes following error message: line
> 45: [.: =: unary operator expected
>
> Also this line:
>
> set `/usr/bin/id`
>
> in the same script ans the same function causes printing a whole environment
> on the screen.
>
> Linux version installed is Mandrakelinux release 10.1

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.

Anyway, we don't want our scripts to fail, even on abnormal systems :)
Could you please try the following patch and see if the problem is
fixed:

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

# Portability comments:

> _______________________________________________
> Linux-HA mailing list
> Linux-HA [at] lists
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
>
>


--
Thanks & regards
Xun Sun
_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems


alanr at unix

Nov 14, 2005, 7:18 PM

Post #3 of 8 (1087 views)
Permalink
Re: ocf-shellfuncs is broken in the last CVS [In reply to]

Serge Dubrouski wrote:
> Hello -
>
> After checking out the latest CVS version of Linux-HA everything stopped
> to work because of the problem in the ocf-shellfuncs.org
> <http://ocf-shellfuncs.org>:
>
> [ $1 = "uid=0(root)" ]
>

This code should work in most circumstances.

/usr/bin/id doesn't print the environment, and set shouldn't either.

But, I think perhaps this code might work better for you:

ocf_is_root() {
case `id` in
*'uid=0(root)'*) true;;
*) false;;
esac
}


--
Alan Robertson <alanr [at] unix>

"Openness is the foundation and preservative of friendship... Let me
claim from you at all times your undisguised opinions." - William
Wilberforce
_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems


carson at taltos

Nov 14, 2005, 7:20 PM

Post #4 of 8 (1097 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


sergeyfd at gmail

Nov 14, 2005, 7:54 PM

Post #5 of 8 (1093 views)
Permalink
RE: ocf-shellfuncs is broken in the last CVS [In reply to]

I wouldn't say that it's abnormal :-):


$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Sep 8 11:20 /bin/sh -> bash*
$ uname -a
Linux aspdev1 2.6.11-6mdk #1 Tue Mar 22 16:04:32 CET 2005 i686 Intel(R)
Xeon(TM) CPU 2.80GHz unknown GNU/Linux
$

The problem with set `/usr/bin/id` is that on Mandrake /usr/bin/id does not
exists. id tool sits in the /usr/bin so to make your code work properly
you'd better put something
ID=`which id`
set `$ID`


And the patch worked well.


-----Original Message-----
From: linux-ha-bounces [at] lists
[mailto:linux-ha-bounces [at] lists]On Behalf Of Xun Sun
Sent: Monday, November 14, 2005 7:05 PM
To: General Linux-HA mailing list
Subject: Re: [Linux-HA] ocf-shellfuncs is broken in the last CVS


Hi Serge,
On 11/15/05, Serge Dubrouski <sergeyfd [at] gmail> wrote:
> Hello -
>
> After checking out the latest CVS version of Linux-HA everything stopped
to
> work because of the problem in the ocf-shellfuncs.org:
>
> [ $1 = "uid=0(root)" ]
>
> This line in the ocf_is_root function causes following error message: line
> 45: [.: =: unary operator expected
>
> Also this line:
>
> set `/usr/bin/id`
>
> in the same script ans the same function causes printing a whole
environment
> on the screen.
>
> Linux version installed is Mandrakelinux release 10.1

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.

Anyway, we don't want our scripts to fail, even on abnormal systems :)
Could you please try the following patch and see if the problem is
fixed:

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

# Portability comments:

> _______________________________________________
> Linux-HA mailing list
> Linux-HA [at] lists
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
>
>


--
Thanks & regards
Xun Sun
_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems


sergeyfd at gmail

Nov 14, 2005, 7:57 PM

Post #6 of 8 (1095 views)
Permalink
RE: ocf-shellfuncs is broken in the last CVS [In reply to]

Alan wrote:

> /usr/bin/id doesn't print the environment, and set shouldn't either.

You are right. But if /usr/bin/id does not exist (my Mandrake case) "set
`/usr/bin/id`" turns into set without parameters which prints environment
:-)

_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems


xun.sun.cn at gmail

Nov 14, 2005, 8:28 PM

Post #7 of 8 (1085 views)
Permalink
Re: ocf-shellfuncs is broken in the last CVS [In reply to]

On 11/15/05, Serge Dubrouski <sergeyfd [at] gmail> wrote:
> I wouldn't say that it's abnormal :-):
>
Ah, sorry, so it was a surprise to me from my very limitted experience :-)

>
> $ ls -l /bin/sh
> lrwxrwxrwx 1 root root 4 Sep 8 11:20 /bin/sh -> bash*
> $ uname -a
> Linux aspdev1 2.6.11-6mdk #1 Tue Mar 22 16:04:32 CET 2005 i686 Intel(R)
> Xeon(TM) CPU 2.80GHz unknown GNU/Linux
> $
>
> The problem with set `/usr/bin/id` is that on Mandrake /usr/bin/id does not
> exists. id tool sits in the /usr/bin so to make your code work properly
> you'd better put something
> ID=`which id`
> set `$ID`
>

I have just committed a fix which should work for systems who have id
in PATH. I think it is the same as your approach. Thanks for spotting
this.

>
> And the patch worked well.
>
>
> -----Original Message-----
> From: linux-ha-bounces [at] lists
> [mailto:linux-ha-bounces [at] lists]On Behalf Of Xun Sun
> Sent: Monday, November 14, 2005 7:05 PM
> To: General Linux-HA mailing list
> Subject: Re: [Linux-HA] ocf-shellfuncs is broken in the last CVS
>
>
> Hi Serge,
> On 11/15/05, Serge Dubrouski <sergeyfd [at] gmail> wrote:
> > Hello -
> >
> > After checking out the latest CVS version of Linux-HA everything stopped
> to
> > work because of the problem in the ocf-shellfuncs.org:
> >
> > [ $1 = "uid=0(root)" ]
> >
> > This line in the ocf_is_root function causes following error message: line
> > 45: [.: =: unary operator expected
> >
> > Also this line:
> >
> > set `/usr/bin/id`
> >
> > in the same script ans the same function causes printing a whole
> environment
> > on the screen.
> >
> > Linux version installed is Mandrakelinux release 10.1
>
> 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.
>
> Anyway, we don't want our scripts to fail, even on abnormal systems :)
> Could you please try the following patch and see if the problem is
> fixed:
>
> --- 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 ]
> }
>
> # Portability comments:
>
> > _______________________________________________
> > Linux-HA mailing list
> > Linux-HA [at] lists
> > http://lists.linux-ha.org/mailman/listinfo/linux-ha
> > See also: http://linux-ha.org/ReportingProblems
> >
> >
>
>
> --
> Thanks & regards
> Xun Sun
> _______________________________________________
> Linux-HA mailing list
> Linux-HA [at] lists
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
>
> _______________________________________________
> Linux-HA mailing list
> Linux-HA [at] lists
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
>
--
Thanks & regards
Xun Sun
_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems


alanr at unix

Nov 14, 2005, 9:27 PM

Post #8 of 8 (1075 views)
Permalink
Re: ocf-shellfuncs is broken in the last CVS [In reply to]

Serge Dubrouski wrote:
> Alan wrote:
>
>> /usr/bin/id doesn't print the environment, and set shouldn't either.
>
> You are right. But if /usr/bin/id does not exist (my Mandrake case) "set
> `/usr/bin/id`" turns into set without parameters which prints environment
> :-)

Ahhh...

Do you have "id" somewhere else then?

Does my suggested change help?


--
Alan Robertson <alanr [at] unix>

"Openness is the foundation and preservative of friendship... Let me
claim from you at all times your undisguised opinions." - William
Wilberforce
_______________________________________________
Linux-HA mailing list
Linux-HA [at] lists
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Linux-HA users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.