[Linux-ha-dev] Re: Question about heartbeat/shellfuncs

Lars Ellenberg Lars.Ellenberg at linbit.com
Wed Aug 9 13:27:03 MDT 2006


/ 2006-08-09 18:41:00 +0100
\ David Lee:
> >
> > > This is probably not sigificant.  But if it is (or if there is a future
> > > chance of its becoming significant) then the second version (the single
> > > parenthesised subshell into a single call to the fifo) may be preferable.
> > >
> > > I'll prepare a local-workspace patch for the:
> > >    (thing1; thing2l thing3) >> fifo
> > > variant and apply it post-2.0.7 shipment.
> >
> > the original version semantics would probably best be matched by using a
> > second cat again, like this:
> >     (echo ">>>"; cat -; echo "<<<") | cat - >> $HA_FIFO
> 
> Hmmm... I don't see any functional difference between my proposed:
>    (echo ">>>"; cat -; echo "<<<") >> $HA_FIFO
> and your proposed:
>    (echo ">>>"; cat -; echo "<<<") | cat - >> $HA_FIFO
> 
> Under what conditions would they behave differently?  What benefit does
> your more complex version have that mine lacks?
> 
> (I'm happy to learn!)

I think the second cat would buffer its input, then when its stdin is
finally closed, write and flush all in one blob into the fifo.

lets strace -f -o ... it (stdin is coming from echo -e "foo 1\nfoo 2"):
# grep -e write.1 no-second-cat with-second-cat 
no-second-cat:4672  write(1, "===\n", 4)              = 4
no-second-cat:4673  write(1, "foo 1\nfoo 2\n", 12)    = 12
no-second-cat:4672  write(1, "===\n", 4)              = 4

with-second-cat:4682  write(1, "===\n", 4)              = 4
with-second-cat:4684  write(1, "foo 1\nfoo 2\n", 12)    = 12
with-second-cat:4682  write(1, "===\n", 4)              = 4
with-second-cat:4685  write(1, "===\nfoo 1\nfoo 2\n===\n", 20) = 20
                                                           
in any case, as long as there are no concurrent users (or they are
"careful", whatever that means), any variation is ok.
when we have concurrency, the second cat is only a band aid, to reduce
the likelyhood of garbled messages.

so this is probably a somewhat esotheric issue, anyways.

and depending on which version of all the tools you have. I think some
versions of cat do their completely own magic about whether or not to
buffer (and tend to do "line" buffering almost all the time), and ignore
the "-u unbuffered" option, which some very old versions of cat not even
know about, and even those that _do_ buffer probably differ in the
buffer size.

-- 
: Lars Ellenberg                                  Tel +43-1-8178292-55 :
: LINBIT Information Technologies GmbH            Fax +43-1-8178292-82 :
: Schoenbrunner Str. 244, A-1120 Vienna/Europe   http://www.linbit.com :


More information about the Linux-HA-Dev mailing list