Page 1 of 1

Re: [Nagios-devel] re patch for nrpe.c : stderr output causes CRC error

Posted: Fri Mar 12, 2004 4:41 am
by Guest
Simon Kitching 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 post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]