Patch: Improved Error Reporting when rotation log file/moving files
Ethan Galstad
nagios at nagios.org
Sun Oct 28 15:59:23 CET 2007
Lars Michelsen wrote:
> Hi Ethan, Hi List,
> I just had some problems with the log rotation of the nagios logfile
> on my productive nagios system. After several trys to get the source
> of the problem I recognized some permission problems. That was a hard
> way to get to that point and fix this.
> Finally this was only possible due to some modifications to the Nagios
> code. True, I could turn on the debug mode, but that's no option on
> the productive system.
>
> Here is a small patch for a little better error reporting to the log
> file when renaming files. This patch should help others to recognize
> the source of their problem much faster.
>
> Peronaly I would add much more error messages for the user to that
> functions but that would also blow up the code.
>
> This patch is for Nagios 2.10, but it should also be applicable to Nagios 3.0.
>
> --- base/utils.c.orig 2007-10-24 17:37:06.000000000 +0200
> +++ base/utils.c 2007-10-24 18:42:52.000000000 +0200
> @@ -4329,6 +4329,7 @@
> int source_fd;
> int dest_fd;
> int bytes_read;
> + char temp_buffer[MAX_INPUT_BUFFER];
>
>
> /* make sure we have something */
> @@ -4338,6 +4339,13 @@
> /* first see if we can rename file with standard function */
> rename_result=rename(source,dest);
>
> + /* the user should know why the logrotation fails */
> + if(rename_result==-1 && errno!=EXDEV) {
> + snprintf(temp_buffer,sizeof(temp_buffer),"ERROR in
> my_rename: unhandled error '%s' while renaming from '%s' to
> '%s'",strerror(errno),source,dest);
> + temp_buffer[sizeof(temp_buffer)-1]='\x0';
> + write_to_all_logs(temp_buffer,NSLOG_PROCESS_INFO);
> + }
> +
> /* an error occurred because the source and dest files are on
> different filesystems */
> if(rename_result==-1 && errno==EXDEV){
>
>
> --
> Lars
>
Thanks! Patch will be in CVS shortly.
Ethan Galstad
Nagios Developer
___
Email: nagios at nagios.org
Web: www.nagios.org
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
More information about the Developers
mailing list