From: Rick Bird Date: Wed, 11 May 2011 22:11:31 +0000 (-0400) Subject: Fixed recursion problem with log_commands. Added Active flag to hook handlers X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=2c1cf17b89f20175473a2f667eac4f5c9c8f8642;p=cobramush.git Fixed recursion problem with log_commands. Added Active flag to hook handlers --- diff --git a/hdrs/modules.h b/hdrs/modules.h index d6715dd..a06dc0e 100644 --- a/hdrs/modules.h +++ b/hdrs/modules.h @@ -41,6 +41,7 @@ struct core_hook_t #define MODHOOK_AROUND 0x04 /* The call hook is an around method.. Take the highest priority & stop */ #define MODHOOK_AFTER 0x08 #define MODHOOK_BEFORE 0x10 +#define MODHOOK_ACTIVE 0x12 /* Is the hook active? */ /* And now our table to load all our chooks at first */ struct chook_table_t { diff --git a/src/modules.c b/src/modules.c index ca727a7..016de4f 100644 --- a/src/modules.c +++ b/src/modules.c @@ -23,7 +23,6 @@ #include "match.h" #include "modules.h" -static int cancel_hooks = 0; struct module_entry_t *module_list = NULL; HASHTAB chook_htab; HASHTAB chook_mevents; /* MUSH Events aliased to Hooks */ @@ -279,8 +278,9 @@ CHook_Run(struct core_entry_t *entry, const char *format, ...) int rval; int (*module_func) (struct core_entry_t * entry, va_list argp); - if (cancel_hooks) + if (entry->up->flags & MODHOOK_ACTIVE) return -1; + entry->up->flags |= MODHOOK_ACTIVE; module_func = NULL; /* Just for initialization purposes */ va_start(argp, format); if (entry->flags & MODHOOK_SOFTCODE) { @@ -289,14 +289,16 @@ CHook_Run(struct core_entry_t *entry, const char *format, ...) } else if (entry->flags & MODHOOK_MODULE) { /* We'll do this code later */ va_end(argp); + entry->up->flags &= ~MODHOOK_ACTIVE; return -1; } else { va_end(argp); + entry->up->flags &= ~MODHOOK_ACTIVE; return -1; } - /* We get ehre something is wrong */ - return -2; + entry->up->flags &= ~MODHOOK_ACTIVE; + return rval; } @@ -371,11 +373,9 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) break; default: /* Bad Format.. don't run & return an error */ - cancel_hooks = 1; /* prevent recursions */ do_rawlog(LT_ERR, "%s:%d -> Unexpected format character '%c' in format \"%s\"", __FILE__, __LINE__, *fptr, format); - cancel_hooks = 0; /* Restore Environment */ copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); free_namedregs(&preserve_namedregs);