[Nagios-devel] patch: fix sigsegv in neb_deregister_callback

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] patch: fix sigsegv in neb_deregister_callback

Post by Guest »

--=-+ilmcyWU9sqtKXKKVVYX
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Tiny patch to fix a sigsegv in neb_deregister_callback when only one
callback of the type exists in the list.

Also enclosed a function that I think would be handy to have in nagios
proper instead of leaving it in my module.

As part of some buffering I'm doing in my module I'm scheduling a
recurring event to call a data dumping function to keep results fresh.
After a fatal error of some kind in the module I need to remove this
event to keep things neat and tidy.
--
Matthew Kent
http://magoazul.com

--=-+ilmcyWU9sqtKXKKVVYX
Content-Disposition: attachment; filename=nagios-2.0b1-neb.patch
Content-Type: text/x-patch; name=nagios-2.0b1-neb.patch; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit

--- ../nagios_orig/base/nebmods.c 2004-12-09 01:00:46.000000000 -0500
+++ base/nebmods.c 2004-12-19 19:55:38.000000000 -0500
@@ -471,9 +471,13 @@
return NEBERROR_CALLBACKNOTFOUND;

else{
- last_callback->next=next_callback;
+ /* only one item in the list */
+ if (temp_callback!=last_callback->next)
+ neb_callback_list[callback_type]=NULL;
+ else
+ last_callback->next=next_callback;
free(temp_callback);
- }
+ }

return OK;
}

--=-+ilmcyWU9sqtKXKKVVYX
Content-Disposition: attachment; filename=nagios-2.0b1-deschedule.patch
Content-Type: text/x-patch; name=nagios-2.0b1-deschedule.patch; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit

--- ../nagios_orig/include/nagios.h.in 2004-12-09 01:48:34.000000000 -0500
+++ include/nagios.h.in 2004-12-19 19:34:37.000000000 -0500
@@ -501,6 +501,7 @@
/**** Monitoring/Event Handler Functions ****/
int schedule_new_event(int,int,time_t,int,unsigned long,void *,int,void *,void *); /* schedules a new timed event */
void reschedule_event(timed_event *,timed_event **); /* reschedules an event */
+int deschedule_event(int,int,void *,void *); /* removes an event from the schedule */
void add_event(timed_event *,timed_event **); /* adds an event to the execution queue */
void remove_event(timed_event *,timed_event **); /* remove an event from the execution queue */
int event_execution_loop(void); /* main monitoring/event handler loop */
--- ../nagios_orig/base/events.c 2004-11-30 12:16:22.000000000 -0500
+++ base/events.c 2004-12-19 19:34:23.000000000 -0500
@@ -743,6 +743,44 @@
}


+/* remove event from schedule */
+int deschedule_event(int event_type, int high_priority, void *event_data, void *event_args){
+ timed_event **event_list;
+ timed_event *temp_event;
+ int found=FALSE;
+
+#ifdef DEBUG0
+ printf("deschedule_event() start\n");
+#endif
+
+ if(high_priority==TRUE)
+ event_list=&event_list_high;
+ else
+ event_list=&event_list_low;
+
+ for(temp_event=*event_list;temp_event!=NULL;temp_event=temp_event->next){
+ if(temp_event->event_data==event_data && temp_event->event_args==event_args){
+ found=TRUE;
+ break;
+ }
+ }
+
+ /* remove the event from the event list */
+ if (found){
+ remove_event(temp_event,event_list);
+ free(temp_event);
+ }
+ else{
+ return ERROR;
+ }
+
+#ifdef DEBUG0
+ printf("deschedule_event() end\n");
+#endif
+
+ return OK;
+ }
+

/* add an event to list ordered by execution time */
void add_event(timed_event *event,timed_event **event_list){

--=-+ilmcyWU9sqtKXKKVVYX--






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