On Tue, 8 Aug 2006, Lars Marowsky-Bree wrote:
> On 2006-08-08T13:03:59, Matthew Soffen <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to get basic sanity check running on FreeBSD.
> >
> > There appears to be a problem with one method in the shellfuncs that
> > cause it to fail on FreeBSD.
> >
> > ha_clustermsg() {
> > cat $* <<-!MSG >> $HA_FIFO
> > >>>
> > `cat`
> > <<<
> > !MSG
> > }
> >
> >
> > The ">>> `cat` <<<" appears to be the problem. If I comment it out,
> > then things work fine. What exactly is this trying to do ?
>
> The message sent via the FIFO is supposed to be enclosed in these as
> begin and end markers.
Hmmm... speaking as an outsider with no direct hand-to-hand combat
experience with "ha_clustermsg()" yet...
"ha_clustermsg()" looks worringly non-intuitive and opaque even to a
relatively experienced Bourne-shell tinkerer. Even if it is technically
correct, it isn't the world's best example of programming clarity!
Is Matt encountering yet another Bourne-vs.-Bash issue lurking hidden in
that dark undergrowth?
Does it need a re-think?
Skimming the source code...
The external view of this function (what its callers expect) seems to be:
input: no arguments; text on "stdin"
output: none/irrelevant
(So let's comment that!)
Is that correct? If so, let's look internally:
> > cat $* <<-!MSG >> $HA_FIFO
What's that about? The "$*" means the function arguments, which for "cat"
should be filenames. But there are no arguments. Surely this version of
cat ("cat filename1 filename2") is not intended here??
Therefore this "cat $*" becomes non-argument "cat", which means copy stdin
to stdout. That, at least, becomes more plausible than the argument-ed
filename version.
So viewed from within, the purpose of the function is (as I understand
LMB's comment) simply to copy the function's stdin into the FIFO but
prepending a ">>>" line and appending a "<<<" line?
Correct?
And a executed (back-tick-ed) `cat` in the middle of that just adds to the
confusion.
If all the above is correct, wouldn't the function be clearer as:
# copy stdin (text) to FIFO, with surrounding ">>>" and "<<<" marker lines.
# no args.; no result
ha_clustermsg() {
echo ">>>" >> $HA_FIFO
cat - >> $HA_FIFO
echo "<<<" >> $HA_FIFO
}
or:
# copy stdin (text) to FIFO, with surrounding ">>>" and "<<<" marker lines.
# no args.; no result
ha_clustermsg() {
(echo ">>>"; cat -; echo "<<<") >> $HA_FIFO
}
or similar?
(Note that the "cat -" could be reduced to "cat". But for clarity I
prefer the "cat -" version, which makes explicit to the maintainers the
intention to use stdin as the data source. Clarity again.)
Matt; LMB; others: thoughts?
--
: 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/