From c8a85e092f12fe10b37169bcdd9d0839600d9f2e Mon Sep 17 00:00:00 2001 From: Andreas Ericsson Date: Tue, 6 Apr 2010 18:49:16 +0200 Subject: [PATCH] state api: Make *_has_new_state() usable without a nebstruct type This patch make the two functions accept the identifier(s) for their respective type along with the state and state_type variables, making it easier to use them from random places (ie, showlog). This also speeds up execution very slightly. Possibly because it no longer has to do quite so many memory offset lookups when checking the state of objects. Naturally, we update the callers accordingly. Signed-off-by: Andreas Ericsson --- hooks.c | 4 ++-- state.c | 28 ++++++++++++++-------------- state.h | 5 ++--- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/hooks.c b/hooks.c index fb9419b..17ef0cd 100644 --- a/hooks.c +++ b/hooks.c @@ -40,7 +40,7 @@ int hook_host_result(int cb, void *data) linfo("Check result processed for host '%s'", ds->host_name); - if (!host_has_new_state(ds)) { + if (!host_has_new_state(ds->host_name, ds->state, ds->state_type)) { linfo("state not changed for host '%s'", ds->host_name); return 0; } @@ -69,7 +69,7 @@ int hook_service_result(int cb, void *data) linfo("Check result processed for service '%s' on host '%s'", ds->service_description, ds->host_name); - if (!service_has_new_state(ds)) { + if (!service_has_new_state(ds->host_name, ds->service_description, ds->state, ds->state_type)) { linfo("state not changed for service '%s' on host '%s'", ds->service_description, ds->host_name); return 0; diff --git a/state.c b/state.c index ebf6898..5e5c74c 100644 --- a/state.c +++ b/state.c @@ -49,36 +49,36 @@ static inline int has_state_change(int *old, int state, int type) return 1; } -int host_has_new_state(nebstruct_host_check_data *ds) +int host_has_new_state(char *host, int state, int type) { int *old_state; - old_state = hash_find(host_states, ds->host_name); + old_state = hash_find(host_states, host); if (!old_state) { - int *state; + int *cur_state; - state = malloc(sizeof(*state)); - *state = CAT_STATE(ds->state, ds->state_type); - hash_add(host_states, ds->host_name, state); + cur_state = malloc(sizeof(*cur_state)); + *cur_state = CAT_STATE(state, type); + hash_add(host_states, host, cur_state); return 1; } - return has_state_change(old_state, ds->state, ds->state_type); + return has_state_change(old_state, state, type); } -int service_has_new_state(nebstruct_service_check_data *ds) +int service_has_new_state(char *host, char *desc, int state, int type) { int *old_state; - old_state = hash_find2(svc_states, ds->host_name, ds->service_description); + old_state = hash_find2(svc_states, host, desc); if (!old_state) { - int *state; + int *cur_state; - state = malloc(sizeof(*state)); - *state = CAT_STATE(ds->state, ds->state_type); - hash_add2(svc_states, ds->host_name, ds->service_description, state); + cur_state = malloc(sizeof(*cur_state)); + *cur_state = CAT_STATE(state, type); + hash_add2(svc_states, host, desc, cur_state); return 1; } - return has_state_change(old_state, ds->state, ds->state_type); + return has_state_change(old_state, state, type); } diff --git a/state.h b/state.h index fadc416..7148226 100644 --- a/state.h +++ b/state.h @@ -1,4 +1,3 @@ -#include "nagios/nebstructs.h" extern int state_init(void); -extern int host_has_new_state(nebstruct_host_check_data *ds); -extern int service_has_new_state(nebstruct_service_check_data *ds); +extern int host_has_new_state(char *host, int state, int type); +extern int service_has_new_state(char *host, char *desc, int state, int type); -- 2.11.4.GIT