Bug #1021

protect against callbacks removing themsevles in nebmods

Added by dnsmichi over 3 years ago. Updated over 3 years ago.

Status:ResolvedStart date:11/24/2010
Priority:NormalDue date:
Assignee:dnsmichi% Done:

100%

Category:-
Target version:Icinga 1.x - 1.3
Icinga Version: OS Version:

Description

From: Andreas Ericsson <ae@op5.se>
Date: Wed, 27 Oct 2010 18:53:25 +0000 (+0000)
Subject: nebmods: Protect against callbacks removing themselves
X-Git-Url: http://git.nagiosprojects.org/?p=nagios.git;a=commitdiff_plain;h=34596d7d75e2219c96865ec38bd70f2a6a0113a2;hp=98d91d403850f4600f2e61af3064584581171666

nebmods: Protect against callbacks removing themselves

Previously a callback deregistering itself from the chain of
callbacks to run at the event-type the callback registered
as (err...), Nagios would segfault since the pointer to the
next callback couldn't be looked up.

This patch takes care of it, making it possible for a module
to unload the callback it's currently running.

Signed-off-by: Andreas Ericsson <ae@op5.se>

Author: Andreas Ericsson <ae@op5.se>
---

diff --git a/base/nebmods.c b/base/nebmods.c
index 1cebdbc..b6bfb43 100644
--- a/base/nebmods.c
+++ b/base/nebmods.c
@@ -554,7 +554,7 @@ int neb_deregister_callback(int callback_type, int (*callback_func)(int,void *))

 /* make callbacks to modules */
 int neb_make_callbacks(int callback_type, void *data){
-    nebcallback *temp_callback=NULL;
+    nebcallback *temp_callback, *next_callback;
     int (*callbackfunc)(int,void *);
     register int cbresult=0;
     int total_callbacks=0;
@@ -570,9 +570,11 @@ int neb_make_callbacks(int callback_type, void *data){
     log_debug_info(DEBUGL_EVENTBROKER,1,"Making callbacks (type %d)...\n",callback_type);

     /* make the callbacks... */
-    for(temp_callback=neb_callback_list[callback_type];temp_callback!=NULL;temp_callback=temp_callback->next){
+    for(temp_callback = neb_callback_list[callback_type];temp_callback;temp_callback=next_callback) {
+        next_callback = temp_callback->next;
         callbackfunc=temp_callback->callback_func;
         cbresult=callbackfunc(callback_type,data);
+        temp_callback = next_callback;

         total_callbacks++;
         log_debug_info(DEBUGL_EVENTBROKER,2,"Callback #%d (type %d) return code = %d\n",total_callbacks,callback_type,cbresult);

Associated revisions

Revision 373cb338
Added by dnsmichi over 3 years ago

core: protect against callbacks removing themsevles in nebmods (Andreas Ericsson) #1021

fixes #1021

History

#1 Updated by dnsmichi over 3 years ago

  • Status changed from Assigned to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF