[Nagios-devel] Checkresult file handling

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] Checkresult file handling

Post by Guest »

Hi,

i watched a 3.0.6 nagios instance with strace and saw the following:

[pid 24308] open("/usr/local/nagios/var/spool/checkresults/cBA2zEX",
O_RDWR|O_CREAT|O_EXCL, 0600) = 5
[pid 24308] rename("/usr/local/nagios/var/spool/checkresults/checkh8exMx",
"/usr/local/nagios/var/spool/checkresults/cBA2zEX") = 0
[pid 24308] close(5) = 0
[pid 24308] open("/usr/local/nagios/var/spool/checkresults/cBA2zEX.ok",
O_WRONLY|O_CREAT|O_TRUNC, 0600) = 5
[pid 24308] close(5) = 0
[pid 24308] unlink("/usr/local/nagios/var/spool/checkresults/checkh8exMx") =
-1 ENOENT (No such file or directory)

In the base/utils.c file is found:

/* move the original file */
result=my_rename(checkresult_file,output_file);

...

/* create an ok-to-go indicator file */
asprintf(&temp_buffer,"%s.ok",output_file);
if((output_file_fd=open(temp_buffer,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR
))>0)
close(output_file_fd);
my_free(temp_buffer);

...

/* delete the original file */
if(result==0)
unlink(checkresult_file);
}

If /* move the original file */ succeeded, then result is 0.
So in /* delete the original file */ a file is unlinked which no linker
exists under this name.

IMHO
if(result!=0) unlink....
would be the correct way.

Gerhard






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked