[Nagios-devel] base/utils.c improvements...

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] base/utils.c improvements...

Post by Guest »

Near line 2740 is the place where an error message is printed if
fcntl(lockfile,...) fails.

The code there is a bit lame.

Please consider changing the code from:

if(fcntl(lockfile,F_SETLK,&lock)<0){
snprintf(temp_buffer,sizeof(temp_buffer)-1,"Lockfile '%s' is
held by PID %d. Bailing out...",lock_file,(int)pid);
write_to_logs_and_console(temp_buffer,NSLOG_RUNTIME_ERROR,TRUE);
cleanup();
exit(ERROR);
}

to:
if(fcntl(lockfile,F_SETLK,&lock)<0){
if ((errno == EACCESS) || (errno == EAGAIN))
snprintf(temp_buffer,sizeof(temp_buffer)-1,"Lockfile
'%s' is held by PID %d. Bailing out...",lock_file,(int)lock.l_pid);
else
snprintf(temp_buffer,sizeof(temp_buffer)-1,"Cannot lock Lockfile '%s'; %s. Bailing out...",lock_file,strerror(errno));
write_to_logs_and_console(temp_buffer,NSLOG_RUNTIME_ERROR,TRUE);
cleanup();
exit(ERROR);
}

Note the change from pid to lock.l_pid for the "existing" error message.

H







This post was automatically imported from historical nagios-devel mailing list archives
Original poster: Harlan.Stenn@pfcs.com
Locked