command pipe concatenated messages

John P. Rouillard rouilj at cs.umb.edu
Mon Dec 29 22:47:22 CET 2003


In message <1072716579.1419.12.camel at linuxws1.internal.priority-health.com>,
Al Tobey writes:

>On Mon, 2003-12-29 at 06:06, Jim Mozley wrote:
>> John P. Rouillard wrote:
>> > I would use ">> $pipe" to append data for two reasons:
>
>Jim was my beta tester for Nagios::Cmd when working out the bugs on
>Solaris (actually, any BSD flavor).

That's wierd. I always thought Solaris was SysV flavor, and the old
SunOS (1-4) was the Berkeley flavor. Is the code the same for any AT&T
derived Unix?

>BSD's don't allow seek() on fifos
>and opening in O_APPEND mode implies a seek to the end of the file,
>which throws an exception.   Linux happily ignores the seek().

That explains it. I wrote my ssh -> nagios command injector to run on
linux. That's obviously why I never saw a problem.  The >> was just a
holdover from writing to real files and not FIFO's.

>> >   2 - atomic writes occur only if file is opened for append IIRC.
>FIFO's cannot be opened in append mode on BSD flavors, as I explained
>earlier.

Yup. Also not opening in append mode appears to work in linux
as well. I ran:

  echo foo > bar& echo bax > bar & echo bam > bar &; sleep 10; cat bar

100 times and always got

  bam
  bax
  foo

Not sure why they were in reverse order, but no concatenation.

>Ahh, the rigors and wonders of portability.
Yup.

The only thing I can think of is manually flushing the filehandle. I
wouldn't expect that to have an effect since the code that Jim wrote
sets $| on the PIPE filehandle, or he used syswrite which should
bypass buffering, but if it works with a 2 second sleep, but not
without it, it sounds like something isn't getting flushed properly,
or maybe some kernel wierdness. The size of the write is far below the
block size on linux let alone solaris (4K right?)

I'll go into the corner and shut up now.

				-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click




More information about the Developers mailing list