Race condition w/nagios.cmd
Jason Martin
jhmartin at toger.us
Sat Jan 24 00:16:32 CET 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
There is a race condition regarding the external command fifo when Nagios
is shutting down. This is especially evident when using nsca in inetd
mode. The problem is that the reading end of the fifo closes prior to the
fifo file being removed. This means that on a busy system many nsca
processes will attempt to open the fifo in between the closing of the pipe
and the removal of the fifo. Those nsca processes will forever be blocked
on the open() of that fifo until they are manually killed.
The fix to this is to unlink the fifo file prior to closing the
reading end of the pipe. I've attached a patch to utils.c (from
nagios-1.1) that reverses the order of the close and unlink to effect
this.
Also, is there a particular reason the nagios.cmd file is removed
/ recreated at launch? I'd think it would prevent some problems to have it
check if an equivalent fifo (ie already has the necessary privs /
name / properties) already exists, plus remove an annoying
problem of failing to launch because that file exists from a previous
instance.
Thanks,
- -Jason Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.3.3 (GNU/Linux)
Comment: pgpenvelope 2.10.2 - http://pgpenvelope.sourceforge.net/
iD8DBQFAEatZl2ODWuqVSBMRAuUAAJ4k9GMOpTYKPC8URHepOYShIyACfgCffkEL
UHMAxbJjETYBXBREgDJbFmg=
=l6Wy
-----END PGP SIGNATURE-----
-------------- next part --------------
--- utils.c Tue Nov 18 16:28:10 2003
+++ utils1.c Fri Jan 23 14:52:50 2004
@@ -2162,13 +2162,17 @@
if(check_external_commands==FALSE)
return OK;
+ /* delete the named pipe prior to closing */
+ /* since there is a race condition of processes */
+ /* opening the pipe after we close and before it is */
+ /* removed */
+ if(unlink(command_file)!=0)
+ return ERROR;
+
/* close the command file */
fclose(command_file_fp);
close(command_file_fd);
- /* delete the named pipe */
- if(unlink(command_file)!=0)
- return ERROR;
#ifdef DEBUG0
printf("close_command_file() end\n");
More information about the Developers
mailing list