FYI, nagios command file pipe may cause passive service corruption

Stanley Hopcroft Stanley.Hopcroft at IPAustralia.Gov.AU
Sat Jun 14 02:12:37 CEST 2003


Dear Sir,

I am writing to thank you for your letter and say,

On Fri, Jun 13, 2003 at 04:28:30PM -0700, Mooney, Ryan wrote:
> 
> Interesting because I clearly saw messages stomping on each other with smaller
> messages than PIPE_BUF.  Hmm...  Looking closer my external commands scripts 
> that pump the data in are all perl and I didn't set the output to the pipe to 
> be unbuffered.  I pre-generate the results for N hosts (where N is big) and shove 
> them in all at once (well I do a seperate printf("...") for each one) perl was 
> probably buffering my write up for me and then blasting a rather large chunk in 
> all at once thus causing the problem. 

Yep. printf? and friends all use stdio so are buffered (depending on
what the library thinks you are talking to, but the only thing that
varies is the degree of buffering).

> Still a little scary since I have to make 
> sure all my write to pipe programs are well behaved in that regard and flush
> thier output after each message (not a big deal, but..).
> 


Would perl -i.bak -pe 's/printf/syswrite s/' -- puff of blue smoke from
                                             -- the chainsaw. Watch your
                                             -- limbs.


# turn pesky printf yada, nada, foo, bar ; into
#  syswrite sprintf yada, nada, foo, bar ;

help ?

Hmm, you would probably enjoy Mr Stein's "Network programming in
Perl". All the IO that's fit to printf? with and without blocking.   

And if you are not acquainted with it, Parallel::ForkManager is a nice
way of collecting data from lots of IO bound processes (eg getting CAM
tables from switches) that you can shove into a named pipe and have it
come out looking wholesome.

Yours sincerely,
-- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.

Here's some gunk from the subroutine called by Parallel::ForkManager

  ## can only write PIPE_BUF bytes without interleaving ##

  my $max_len = 1 ;
  map { my $x; $max_len = $x if ($x = length($_)) > $max_len }
@dot1dTpFdbTable ;
  my $posix_pipe_buf = PIPE_BUF ;
  $posix_pipe_buf -= 42 ;                               # largest known
'switch block' header.
  my $mac_per_pipe_buff = int( $posix_pipe_buf/$max_len ) ;

  while ( @pipe_buff = splice(@dot1dTpFdbTable, 0,
$mac_per_pipe_buff) ) {
    $pipe_buff = "switch: $ip_address $sysDescr\n" ;

                                                        # FIXME
$sysDescr rubbish !!!

    $pipe_buff .= "@pipe_buff\n" ;                      # same as
join(" ", @pipe_buff) . "\n"

                                                        # If buffered io
is used (print FIFO), the
                                                        # output from
writers is interleaved, regardless
                                                        # of the number
of bytes written.

    $nwrite = syswrite(WRITER, $pipe_buff, PIPE_BUF) ;
    die "syswrite(WRITER, pipe_buff, PIPE_BUF) for switch: $switch
failed: $!\n" if ! defined $nwrite ;
  }




-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list