re patch for nrpe.c : stderr output causes CRC error
michael at optusnet.com.au
michael at optusnet.com.au
Fri Mar 12 13:30:39 CET 2004
Simon Kitching <simon at ecnetwork.co.nz> writes:
> Hi Ethan,
>
> I see you've applied both my patches - thanks.
>
> There seems to be a glitch with this one, though:
> [line 235, nrpe.c]
>
> /* redirect STDERR to /dev/null
> close(2);
> open("/dev/null",O_WRONLY);
>
> Note the missing close-of-comment, which turns all the above lines into
> comments.
Simon, could I mention that that isn't very good code?
In particular, if something does
close(0);
and then exec()'s your program, things won't
behave as you expect.
Much safer to do
int fd;
fd = open("/dev/null", O_WRONLY);
if (fd != 2) {
dup2(fd, 2);
close(fd);
}
(the dup2() will do a close on stderr first if needed).
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
More information about the Developers
mailing list