command pipe concatenated messages

John P. Rouillard rouilj at cs.umb.edu
Fri Dec 26 08:39:39 CET 2003


In message <3FE81E6D.6030202 at exponential-e.com>,
Jim Mozley writes:
>The issue I see is with multiple passive checks becoming concatenated, 
>so I end up with events like this:
>
>My service is Up Some description[1065056739]
>PROCESS_SERVICE_CHECK_RESULT:my-host:my-service:0:Some description.
>
>Where another passive check becomes part of the description field of the 
>previous check.
>
>I am using some perl code to submit commands containing:
>
>
>open(PIPE, "> $pipe") or croak "Cannot open pipe $!";

I would use ">> $pipe" to append data for two reasons:

  1 - > clobbers data already existing in files, not sure about in pipes
  2 - atomic writes occur only if file is opened for append IIRC.

>flock(PIPE, LOCK_EX);

This should guarantee only one process is accessing the file, but I
think you have already written to the file by using > in your open, so
there may be a race condition.

>print PIPE "$cmd";
># wait before releasing lock so we don't overlap cmds to Nagios
>sleep 2;
>close PIPE or croak "Cannot close pipe $!"; # also releases lock

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