[Nagios-devel] command pipe concatenated messages

Jim Mozley jim.mozley at exponential-e.com
Mon Dec 29 02:41:07 UTC 2003


Stanley Hopcroft wrote:



>>I should be writing less than PIP_BUF bytes, although I'm not 
>>specifically checking. In the case where I can see the concatenation of 
>>messages it is always less that the max amount. In fact I haven't seen 
>>any messages greater than this.
>>
> 
> 
> you won't - all of the IO (both system and Perl) - requires the coder to
> explicity check for errors.

Yep, I understand this. I could be paranoid and check the message length 
and truncate if beyond a certain size, but I know these are syslog 
messages and are less than the PIP_BUF size by their nature.

>>I am using print to output the message to the pipe as I am using open. 
>>If I was using sysopen I guess I'd use syswrite. Is this what you mean?
>>
> 
> 
> This may be useful: 
> 
> My understanding is 
> 
> 1 print always uses (buffered) stdio; syswrite is simply a badly named
> Perl interface to the system (unbuffered) write() system call.

Presumably as opposed to the perl write function, which I think also 
uses buffered I/O.

> 
> Never use print with things like sockets and multi-user pipes.
> 
> 2 sysopen is simply another interface to the open() system call.
> 
> Unlike Perl open, it has no magic (eg read from or  to pipes), and lets
> you sepcify file modes and stuff.
> 
> If you haven't already done so, you may like to consider 
> 
> 1 ignoring sys?open
> 
> 2 s/print/write()/g

Checking the perldoc in light of your suggestions I found syswrite does 
unbuffered I/O. So I'll change the print to syswrite and failing this I 
can change $| as in perlfaq5.

Thanks for the help,

Jim





More information about the Nagios-devel mailing list