[Nagios-checkins] nagios/xdata xpddefault.c,1.48,1.49
Nagios network monitoring software is enterprise server monitoring
Brought to you by:
egalstad,
sawolf-nagios
From: Andreas E. <ag...@us...> - 2010-10-28 12:32:38
|
Update of /cvsroot/nagios/nagios/xdata In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv22690/xdata Modified Files: xpddefault.c Log Message: xpddefault: Use a mutex when writing to and updating perfdata files Running commands doesn't need this, but a combination of threads writing, opening and closing the xpddefault_*_perfdata_fp streams is a recipe for disaster. At least the locks are very short-lived, and should never even block unless threads from modules also try to update the performance data files. Signed-off-by: Andreas Ericsson <ae...@op...> Index: xpddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xpddefault.c,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** xpddefault.c 28 Oct 2010 12:31:40 -0000 1.48 --- xpddefault.c 28 Oct 2010 12:32:30 -0000 1.49 *************** *** 70,73 **** --- 70,75 ---- + static pthread_mutex_t xpddefault_host_perfdata_fp_lock; + static pthread_mutex_t xpddefault_service_perfdata_fp_lock; /******************************************************************/ *************** *** 698,705 **** log_debug_info(DEBUGL_PERFDATA,2,"Processed service performance data file output: %s\n",processed_output); ! /* write the processed output line containing performance data to the service perfdata file */ fputs(processed_output,xpddefault_service_perfdata_fp); ! fputs("\n",xpddefault_service_perfdata_fp); fflush(xpddefault_service_perfdata_fp); /* free memory */ --- 700,709 ---- log_debug_info(DEBUGL_PERFDATA,2,"Processed service performance data file output: %s\n",processed_output); ! /* lock, write to and unlock host performance data file */ ! pthread_mutex_lock(&xpddefault_service_perfdata_fp_lock); fputs(processed_output,xpddefault_service_perfdata_fp); ! fputc('\n',xpddefault_service_perfdata_fp); fflush(xpddefault_service_perfdata_fp); + pthread_mutex_unlock(&xpddefault_service_perfdata_fp_lock); /* free memory */ *************** *** 739,746 **** log_debug_info(DEBUGL_PERFDATA,2,"Processed host performance data file output: %s\n",processed_output); ! /* write the processed output line containing performance data to the host perfdata file */ ! fputs(processed_output,xpddefault_host_perfdata_fp); ! fputs("\n",xpddefault_host_perfdata_fp); fflush(xpddefault_host_perfdata_fp); /* free memory */ --- 743,752 ---- log_debug_info(DEBUGL_PERFDATA,2,"Processed host performance data file output: %s\n",processed_output); ! /* lock, write to and unlock host performance data file */ ! pthread_mutex_lock(&xpddefault_host_perfdata_fp_lock); ! fputs(processed_output, xpddefault_host_perfdata_fp); ! fputc('\n', xpddefault_host_perfdata_fp); fflush(xpddefault_host_perfdata_fp); + pthread_mutex_unlock(&xpddefault_host_perfdata_fp_lock); /* free memory */ *************** *** 769,775 **** return OK; - /* close the performance data file */ - xpddefault_close_host_perfdata_file(); - /* init macros */ memset(&mac, 0, sizeof(mac)); --- 775,778 ---- *************** *** 793,806 **** log_debug_info(DEBUGL_PERFDATA,2,"Processed host performance data file processing command line: %s\n",processed_command_line); /* run the command */ my_system(&mac, processed_command_line,xpddefault_perfdata_timeout,&early_timeout,&exectime,NULL,0); clear_volatile_macros(&mac); /* check to see if the command timed out */ if(early_timeout==TRUE) logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning: Host performance data file processing command '%s' timed out after %d seconds\n",processed_command_line,xpddefault_perfdata_timeout); - /* re-open the performance data file */ - xpddefault_open_host_perfdata_file(); /* free memory */ --- 796,815 ---- log_debug_info(DEBUGL_PERFDATA,2,"Processed host performance data file processing command line: %s\n",processed_command_line); + /* lock and close the performance data file */ + pthread_mutex_lock(&xpddefault_host_perfdata_fp_lock); + xpddefault_close_host_perfdata_file(); + /* run the command */ my_system(&mac, processed_command_line,xpddefault_perfdata_timeout,&early_timeout,&exectime,NULL,0); clear_volatile_macros(&mac); + /* re-open and unlock the performance data file */ + xpddefault_open_host_perfdata_file(); + pthread_mutex_unlock(&xpddefault_host_perfdata_fp_lock); + /* check to see if the command timed out */ if(early_timeout==TRUE) logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning: Host performance data file processing command '%s' timed out after %d seconds\n",processed_command_line,xpddefault_perfdata_timeout); /* free memory */ *************** *** 828,834 **** return OK; - /* close the performance data file */ - xpddefault_close_service_perfdata_file(); - /* init macros */ memset(&mac, 0, sizeof(mac)); --- 837,840 ---- *************** *** 852,857 **** --- 858,872 ---- log_debug_info(DEBUGL_PERFDATA,2,"Processed service performance data file processing command line: %s\n",processed_command_line); + /* lock and close the performance data file */ + pthread_mutex_lock(&xpddefault_service_perfdata_fp_lock); + xpddefault_close_service_perfdata_file(); + /* run the command */ my_system(&mac, processed_command_line,xpddefault_perfdata_timeout,&early_timeout,&exectime,NULL,0); + + /* re-open and unlock the performance data file */ + xpddefault_open_service_perfdata_file(); + pthread_mutex_unlock(&xpddefault_service_perfdata_fp_lock); + clear_volatile_macros(&mac); *************** *** 860,866 **** logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning: Service performance data file processing command '%s' timed out after %d seconds\n",processed_command_line,xpddefault_perfdata_timeout); - /* re-open the performance data file */ - xpddefault_open_service_perfdata_file(); - /* free memory */ my_free(raw_command_line); --- 875,878 ---- |